Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all windows-illegal characters from filenames #300

Merged
merged 1 commit into from
Dec 8, 2016
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
3 changes: 2 additions & 1 deletion lib/rspec_api_documentation/views/markup_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def dirname
end

def filename
basename = description.downcase.gsub(/\s+/, '_').gsub(Pathname::SEPARATOR_PAT, '')
special_chars = /[<>:"\/\\|?*]/
basename = description.downcase.gsub(/\s+/, '_').gsub(special_chars, '')
basename = Digest::MD5.new.update(description).to_s if basename.blank?
"#{basename}.#{extension}"
end
Expand Down
11 changes: 10 additions & 1 deletion spec/views/html_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe RspecApiDocumentation::Views::HtmlExample do
let(:metadata) { { :resource_name => "Orders" } }
let(:group) { RSpec::Core::ExampleGroup.describe("Orders", metadata) }
let(:rspec_example) { group.example("Ordering a cup of coffee") {} }
let(:description) { "Ordering a cup of coffee" }
let(:rspec_example) { group.example(description) {} }
let(:rad_example) do
RspecApiDocumentation::Example.new(rspec_example, configuration)
end
Expand All @@ -19,6 +20,14 @@
expect(html_example.filename).to eq("ordering_a_cup_of_coffee.html")
end

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

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

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