Skip to content

Commit

Permalink
Fix links with ampersands in URL (#95)
Browse files Browse the repository at this point in the history
This appears to be needed due to a long standing bug in nokogiri, see commits below. All '&' now get replaced with
'&'. 

* Escape all ampersands in relationship nodes with '&'

Without this Nokogiri will downcase the attributes for some reason
which I assume must be expected behavior since the issue hasn't been
fixed.
Issue Reference: sparklemotion/nokogiri#961

* Update HTML insertion integration test

This test ensures URL get their ampeersands escaped correctly
without interfering with ones that are already escaped.
  • Loading branch information
stadelmanma committed Mar 7, 2018
1 parent bf18e55 commit 414ee7f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sablon/document_object_model/relationships.rb
Expand Up @@ -104,7 +104,7 @@ def next_rid
# Builds the relationship WordML tag and returns it
def relationship_tag(rel_attr)
attr_str = rel_attr.map { |k, v| %(#{k}="#{v}") }.join(' ')
"<Relationship #{attr_str}/>"
"<Relationship #{attr_str}/>".gsub(/&(?!amp;)/, '&amp;')
end
end
end
Expand Down
Binary file modified test/fixtures/html_sample.docx
Binary file not shown.
Binary file modified test/fixtures/insertion_template.docx
Binary file not shown.
3 changes: 2 additions & 1 deletion test/html_test.rb
Expand Up @@ -20,7 +20,8 @@ def test_generate_document_from_template_with_styles_and_html
'html:content' => content,
inline_content: {
'html:should' => '<b><span style="color: #123456">should</span></b>',
'html:github' => '<a href="http://www.github.com" style="color: #0000FF">GitHub</a>'
'html:github' => '<a href="http://www.github.com" style="color: #0000FF">GitHub</a>',
'html:google' => '<a href="https://www.google.com.eg/?gfe_rd=cr&dcr=0&amp;ei=mSKcWqXgIIKZX9zomrAL" style="color: #0000FF">Google</a>'
}
}
template.render_to_file output_path, context
Expand Down

0 comments on commit 414ee7f

Please sign in to comment.