Skip to content

Commit

Permalink
Merge pull request #378 from acl-services/remove-special-chars-from-d…
Browse files Browse the repository at this point in the history
…irnames

Remove special chars from dirnames
  • Loading branch information
oestrich authored Apr 11, 2018
2 parents 8b1938e + 43b66db commit 87cb1d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rspec_api_documentation/views/markup_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module RspecApiDocumentation
module Views
class MarkupExample < Mustache
SPECIAL_CHARS = /[<>:"\/\\|?*]/.freeze

def initialize(example, configuration)
@example = example
@host = configuration.curl_host
Expand All @@ -19,12 +21,11 @@ def respond_to?(method, include_private = false)
end

def dirname
resource_name.to_s.downcase.gsub(/\s+/, '_').gsub(":", "_")
sanitize(resource_name.to_s.downcase)
end

def filename
special_chars = /[<>:"\/\\|?*]/
basename = description.downcase.gsub(/\s+/, '_').gsub(special_chars, '')
basename = sanitize(description.downcase)
basename = Digest::MD5.new.update(description).to_s if basename.blank?
"#{basename}.#{extension}"
end
Expand Down Expand Up @@ -87,6 +88,10 @@ def format_scope(unformatted_scope)
def content_type(headers)
headers && headers.fetch("Content-Type", nil)
end

def sanitize(name)
name.gsub(/\s+/, '_').gsub(SPECIAL_CHARS, '')
end
end
end
end
8 changes: 8 additions & 0 deletions spec/views/html_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
end
end

context "when resource name contains special characters for Windows OS" do
let(:metadata) { { :resource_name => 'foo<>:"/\|?*bar' } }

it "removes them" do
expect(html_example.dirname).to eq("foobar")
end
end

describe "multi-character example name" do
let(:metadata) { { :resource_name => "オーダ" } }
let(:label) { "Coffee / Teaが順番で並んでいること" }
Expand Down

0 comments on commit 87cb1d4

Please sign in to comment.