Skip to content

Commit

Permalink
resolves #3765 download and embed custom remote stylesheet if allow-u…
Browse files Browse the repository at this point in the history
…ri-read is set
  • Loading branch information
mojavelinux committed Oct 23, 2020
1 parent 4f15529 commit eea4a23
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -63,6 +63,7 @@ Improvements::
* Skip unused default attribute assigments for embedded document
* Allow a URL macro to have a preceding single or double quote (#3376)
* Add support for erubi template engine; use it in place of erubis in test suite; note the use of erubis is deprecated (#3737)
* Download and embed remote custom stylesheet if allow-uri-read is set (#3765)

Build / Infrastructure::

Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/converter/html5.rb
Expand Up @@ -138,7 +138,7 @@ def convert_document node
result << %(<link rel="stylesheet" href="#{node.normalize_web_path((node.attr 'stylesheet'), (node.attr 'stylesdir', ''))}"#{slash}>)
else
result << %(<style>
#{node.read_asset node.normalize_system_path((node.attr 'stylesheet'), (node.attr 'stylesdir', '')), warn_on_failure: true, label: 'stylesheet'}
#{node.read_contents (node.attr 'stylesheet'), start: (node.attr 'stylesdir'), warn_on_failure: true, label: 'stylesheet'}
</style>)
end
end
Expand Down
51 changes: 51 additions & 0 deletions test/api_test.rb
Expand Up @@ -1153,6 +1153,23 @@ def for name
refute_empty styles.strip
end

test 'should embed remote stylesheet by default if SafeMode is less than SECURE and allow-uri-read is set' do
input = <<~'EOS'
= Document Title
text
EOS

output = using_test_webserver do
Asciidoctor.convert input, safe: Asciidoctor::SafeMode::SERVER, standalone: true, attributes: { 'allow-uri-read' => '', 'stylesheet' => %(http://#{resolve_localhost}:9876/fixtures/custom.css) }
end
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
styles = stylenode.content
refute_nil styles
refute_empty styles.strip
assert_include 'color: green', styles
end

test 'should not allow linkcss be unset from document if SafeMode is SECURE or greater' do
input = <<~'EOS'
= Document Title
Expand Down Expand Up @@ -1244,6 +1261,40 @@ def for name
refute_empty styles.strip
end

test 'should embed custom remote stylesheet if SafeMode is less than SECURE and allow-uri-read is set' do
input = <<~'EOS'
= Document Title
text
EOS

output = using_test_webserver do
Asciidoctor.convert input, safe: Asciidoctor::SafeMode::SERVER, standalone: true, attributes: { 'allow-uri-read' => '', 'stylesheet' => %(http://#{resolve_localhost}:9876/fixtures/custom.css) }
end
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
styles = stylenode.content
refute_nil styles
refute_empty styles.strip
assert_include 'color: green', styles
end

test 'should embed custom stylesheet in remote stylesdir if SafeMode is less than SECURE and allow-uri-read is set' do
input = <<~'EOS'
= Document Title
text
EOS

output = using_test_webserver do
Asciidoctor.convert input, safe: Asciidoctor::SafeMode::SERVER, standalone: true, attributes: { 'allow-uri-read' => '', 'stylesdir' => %(http://#{resolve_localhost}:9876/fixtures), 'stylesheet' => 'custom.css' }
end
stylenode = xmlnodes_at_css 'html:root > head > style', output, 1
styles = stylenode.content
refute_nil styles
refute_empty styles.strip
assert_include 'color: green', styles
end

test 'should convert source file and write result to adjacent file by default' do
sample_input_path = fixture_path('sample.adoc')
sample_output_path = fixture_path('sample.html')
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/custom.css
@@ -0,0 +1,3 @@
mark {
color: green;
}

0 comments on commit eea4a23

Please sign in to comment.