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

Exporting an a Tag with & character in the href the exported file is corrupted #94

Closed
ahmedelmahalawey opened this issue Mar 4, 2018 · 6 comments
Labels

Comments

@ahmedelmahalawey
Copy link
Contributor

ahmedelmahalawey commented Mar 4, 2018

When the href value of a Tag contains special characters like ampersand, the exported file is corrupted. After investigating I found out that the Relationship tag and its attributes get lowercased when added to the @relationships object.

for example:

html text = "https://www.google.com.eg/?gfe_rd=cr&dcr=0&ei=mSKcWqXgIIKZX9zomrAL"

exported xml node = <relationship type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" target="https://www.google.com.eg/?gfe_rd=cr&amp;dcr=0&amp;ei=WAGcWsyWCbKZX-nZAg" targetmode="External" id="rId15">

expected exported xml node = <Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="https://www.google.com.eg/?gfe_rd=cr&amp;dcr=0&amp;ei=WAGcWsyWCbKZX-nZAg" TargetMode="External" Id="rId15">

@stadelmanma stadelmanma added the bug label Mar 5, 2018
@stadelmanma
Copy link
Collaborator

This appears to be a noted issue with Nokogiri when there isn't a DOCTYPE (which MS Word docs lack) sparklemotion/nokogiri#961. I think the easy fix is simply gsubing the & with &amp; because thats all MS Word appears to do.

@amrfaisal
Copy link

amrfaisal commented Mar 6, 2018

@stadelmanma : Even if we send the original HTML with &amp; to Sablon, it gets transformed back to & at this line:

@target = node.attributes['href'].value

@stadelmanma
Copy link
Collaborator

@amrfaisal can you test this against #95? I think that should fix things since I gsub the ampersand out during creation of the tag which is after the line in ast.rb you flagged. I also dropped a line on the relevant Nokogiri issue but given that it's been around since 2013 I doubt things will change.

@amrfaisal
Copy link

@stadelmanma : Tested and working as expected, thanks a lot for the quick fix, please notify me when this pull request got merged.

@stadelmanma
Copy link
Collaborator

@amrfaisal there is an update sablon release on ruby gems, 0.2.1, with this fix. Thanks for your help testing!

@amrfaisal
Copy link

That was fast, tested the new release, and it's working as expected. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants