Repository navigation
Fix serializing noscript content - #331
Conversation
|
I don't think it is just a resource question: When these nodes are suddenly present in the DOM tree, selectors might match them and wrong data might be extracted. So at least, this would be a breaking change. And then again, I would not mind saving resources either instead of building a part of the DOM tree that I do not care about. I do agree, that the values for parsing and serialization should match and the current behaviour here is a bug. What do you think about a |
|
I would not like this as a Cargo feature. They are too messy for configuration. If this really should be changeable it should be at runtime. The I would rather split it into two PR then. For now, use true as a default so it's just the bug fix for now. And later in a breaking change release this behavior can be changed? (scraper still uses |
I agree in principle, but then we have to thread it through so that equal values for parsing and serialization are ensured. If that is possible without too much overhead and complexity and you are willing to do the extra work, this would also be viable IMO.
This is certainly reasonable.
Even in semver bump, this is icky as it is a silent behavioural change. So everything compiles, probably even tests (because your tests do not include |
|
I went for using the Good thing for a follow-up: It should be possible to parse with scripting disabled and serialize with scripting enabled for the same roundtrip output. So I think only the parser needs configurable |
This consistently uses scripting_enabled: true from the html5ever default and thereby ensures that `scripting_enabled` is the same for parsing and serializing. If its not (like before this commit) it escapes the content which results in broken noscript contents.
85e5e5e to
946193f
Compare
Also, ensure that
scripting_enabledis the same for parsing and serializing. If it's not (like before this commit) it escapes the content which results in brokennoscriptcontents.My first issue was that content of
noscriptwas "destroyed" (= needlessly escaped) when I used scraper for parsing, then changing something unrelated and then serializing it back to an HTML string (basicallyHtml::parse_document(input).html()), but I didn't understand why.And it gets worse when it's done multiple times in a row on the output of the run before.
Turns out,
html5everusestrueas aDefaultforscripting_enabledfor both parsing and serializing. Currently, scraper overrides this default for serializing but not for parsing which breaks the output. They need to be the same for parsing and serializing. Both true or both false does not matter as long as they are the same.(Test case
noscript_parse_roundtrip_stays_the_sameprevent this from happening again.)Looking into #123 the discussion is between disabling or enabling it. A browser definitely wants to enable this to reduce tree complexity and therefore resource reasons so thehtml5everdefault is to enable it. That saves resources for contents which are not needed as a node tree as they are not needed to be shown anyway.But for a scraper I don't see a reason to save on resources here.
Either you don't care about it, then it works with parsing and serializing either way. Or you want to select it, then you can select it as a whole either way. To get the content, you can still use
inner_htmland get aString. But with disabling it you can also select things within which is what this library wants to achieve in the first place: select things within the node tree. So I think the only logical choice is to disable it. And for the reasons I just mentioned I don't think it needs to be configurable either.So for me, it's a bug fix
with the side effect of allowing for #123 with the chosen value.