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

Text is not escaped on write #32

Closed
mernen opened this issue Mar 20, 2017 · 5 comments · Fixed by #56
Closed

Text is not escaped on write #32

mernen opened this issue Mar 20, 2017 · 5 comments · Fixed by #56

Comments

@mernen
Copy link

mernen commented Mar 20, 2017

When producing XML, text on any field is written unescaped, which in practice means any feed with HTML content will be broken.

Example:

extern crate rss;

use rss::Channel;

fn main() {
    let input = r#"
        <rss version="2.0">
            <channel>
                <title>My &lt;feed&gt;</title>
            </channel>
        </rss>
    "#;
    let channel = input.parse::<Channel>().unwrap();
    let output = channel.to_string();

    println!("Output:\n{}", output);

    // test roundtrip
    output.parse::<Channel>().expect("Couldn't read back output");
}

The final roundtrip parse fails due to a literal <feed> that was written.

Looking into the quick-xml crate, I couldn't find it clearly stated anywhere, but from the source code, Event::Text is meant to hold only escaped content. (This is still true on quick-xml 0.6, where a number of things changed compared to 0.4.)

@tafia
Copy link
Contributor

tafia commented Mar 20, 2017

Quick-xml doesn't handle escaping characters when writing. Shouldn't be too complicated to add.

@jameshurst jameshurst mentioned this issue Jun 4, 2017
@frewsxcv
Copy link
Member

Should this be reported upstream to quickxml or is this something that should be added for this 'rss' crate?

@tafia
Copy link
Contributor

tafia commented Jun 18, 2017

This should probably be better on quick-xml. Unfortunately I don't have much time at the moment.

@huntiep huntiep mentioned this issue Jul 25, 2017
@huntiep
Copy link

huntiep commented Jul 25, 2017

What would be involved in fixing this? Would it just require escaping Event::Text on write_event, or is there more involved? If that's all involved I think I have a patch here.

@tafia
Copy link
Contributor

tafia commented Jul 25, 2017

Thanks!
Can you do a PR? This is not perfect but it is already much better than the current situation.
The big missing part is for special characters represented by their ASCII code.
I guess that your patch with a proper comment would be a good improvement already

bors bot added a commit that referenced this issue Aug 18, 2017
56: update to quick-xml 0.9.0 r=frewsxcv

I've just updated quick-xml to use v0.9.0.
This version includes a PR to escape some characters on Text events: tafia/quick-xml#78

This may close #32
@bors bors bot closed this as completed in #56 Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants