Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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