Skip to content

Commit 87cb1d4

Browse files
authored
Merge pull request #378 from acl-services/remove-special-chars-from-dirnames
Remove special chars from dirnames
2 parents 8b1938e + 43b66db commit 87cb1d4

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/rspec_api_documentation/views/markup_example.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module RspecApiDocumentation
44
module Views
55
class MarkupExample < Mustache
6+
SPECIAL_CHARS = /[<>:"\/\\|?*]/.freeze
7+
68
def initialize(example, configuration)
79
@example = example
810
@host = configuration.curl_host
@@ -19,12 +21,11 @@ def respond_to?(method, include_private = false)
1921
end
2022

2123
def dirname
22-
resource_name.to_s.downcase.gsub(/\s+/, '_').gsub(":", "_")
24+
sanitize(resource_name.to_s.downcase)
2325
end
2426

2527
def filename
26-
special_chars = /[<>:"\/\\|?*]/
27-
basename = description.downcase.gsub(/\s+/, '_').gsub(special_chars, '')
28+
basename = sanitize(description.downcase)
2829
basename = Digest::MD5.new.update(description).to_s if basename.blank?
2930
"#{basename}.#{extension}"
3031
end
@@ -87,6 +88,10 @@ def format_scope(unformatted_scope)
8788
def content_type(headers)
8889
headers && headers.fetch("Content-Type", nil)
8990
end
91+
92+
def sanitize(name)
93+
name.gsub(/\s+/, '_').gsub(SPECIAL_CHARS, '')
94+
end
9095
end
9196
end
9297
end

spec/views/html_example_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
end
2929
end
3030

31+
context "when resource name contains special characters for Windows OS" do
32+
let(:metadata) { { :resource_name => 'foo<>:"/\|?*bar' } }
33+
34+
it "removes them" do
35+
expect(html_example.dirname).to eq("foobar")
36+
end
37+
end
38+
3139
describe "multi-character example name" do
3240
let(:metadata) { { :resource_name => "オーダ" } }
3341
let(:label) { "Coffee / Teaが順番で並んでいること" }

0 commit comments

Comments
 (0)