Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Escape \X in stylesheets
Browse files Browse the repository at this point in the history
  • Loading branch information
maxd committed Oct 12, 2013
1 parent 9408a46 commit 02f4461
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pdfkit/pdfkit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def append_stylesheets

stylesheets.each do |stylesheet|
if @source.to_s.match(/<\/head>/)
@source = Source.new(@source.to_s.gsub(/(<\/head>)/, style_tag_for(stylesheet)+'\1'))
@source = Source.new(@source.to_s.gsub(/(<\/head>)/) {|s| style_tag_for(stylesheet) + s })
else
@source.to_s.insert(0, style_tag_for(stylesheet))
end
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/example_with_hex_symbol.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test:before {
content: '\2039';
}
8 changes: 8 additions & 0 deletions spec/pdfkit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@
pdfkit.source.to_s.should include("<style>#{File.read(css)}</style></head>")
end

it "should escape \\X in stylesheets" do
pdfkit = PDFKit.new("<html><head></head><body>Hai!</body></html>")
css = File.join(SPEC_ROOT,'fixtures','example_with_hex_symbol.css')
pdfkit.stylesheets << css
pdfkit.to_pdf
pdfkit.source.to_s.should include("<style>#{File.read(css)}</style></head>")
end

it "should throw an error if it is unable to connect" do
pdfkit = PDFKit.new("http://google.com/this-should-not-be-found/404.html")
lambda { pdfkit.to_pdf }.should raise_error
Expand Down

0 comments on commit 02f4461

Please sign in to comment.