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

Escape list prefix, suffix and bullet chars in the CSS rules #550

Merged
merged 6 commits into from
Apr 30, 2014

Conversation

peitschie
Copy link
Contributor

Various browser cope differently with unescaped characters in a CSS content block, though all browsers agree it is a bad thing. WebKit will throw an error, Chrome & FF will "guess" where the rule ends (and usually get it wrong).

This patch does 2 things to fix this:

  • Consistently use double-quotes to quote strings
  • Escape backspace and double-quote chars in the CSS-related content

The vast amount of testing code is primarily creating a string tokenizer able to parse out the displayed text across Chrome/WebKit + FF. As there is no simple way to get the "rendered text" from a pseudo-element, a lot of code is required to compute this. There are tests included for the hand-rolled tokenizer as well to ensure proper function.

No tests have been added for OdfCanvas, as the existing list logic in here is destined (sooner rather than later) to be merged into the newer list CSS translation class.

2 Additional tweaks included in this patch

  • Remove some try-catch blocks that immediately rethrow the caught exception
  • Remove unused webodf/tests/test_odt directory

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/1542/

@@ -0,0 +1,674 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visual-tests.odt -> visual-tests.fodt, as fodt is the usual suffix for flat ODT files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@peitschie
Copy link
Contributor Author

I've also dropped commit 4045c79 (fixing the tests in FF) in preference to the simpler fix in PR #564.

@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/1548/

// Content needs to be on a new line if it contains slashes due to a bug in older versions of webkit
// E.g., the one used in the qt runtime tests - https://bugs.webkit.org/show_bug.cgi?id=35010
content = '"' + escapeCSSString(prefix) + '"\n';
}

if (stylemap.hasOwnProperty(style)) {
content += " counter(list, " + stylemap[style] + ")";
} else if (style) {
content += "'" + style + "';";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"'" -> '"' here as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unimportant. The specs allow both double and single quoted strings.. the main reason I changed the others to double-quoted was so I only had to escape a single type of quote. I couldn't think of any harm caused by leaving this alone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. But in the PR text you say "Consistently use double-quotes to quote strings" :) So it is rather "More consistenly" ? Also is not consistent with the copy in ListStylesToCss.
Hm. How quick will #565 be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Good points. Am I still allowed to land this PR if it is only "more" consistent? ^_^.

#565 is @satsuper's primary goal. The code is ready, and he's just fighting with creating some decent unit tests for it. So I expect it to land within the next week or two (assuming you have the spare bandwidth to review of course!).

This directory has never been used, even within the commit that added it
These effectively act as slightly expensive no-ops. There is no need
for them to be present.
Various browser cope differently with unescaped characters in a CSS
content block, though all browsers agree it is a bad thing. WebKit
will throw an error, Chrome & FF will "guess" where the rule ends
(and usually get it wrong).

This patch does 2 things to fix this:
- Consistently use double-quotes to quote strings
- Escape backspace and double-quote chars in the CSS-related content

The vast amount of testing code is primarily creating a string tokenizer
able to parse out the displayed text across Chrome/WebKit + FF. As there
is no simple way to get the "rendered text" from a pseudo-element, a lot
of code is required to compute this. There are tests included for the
hand-rolled tokenizer as well to ensure proper function.

No tests have been added for OdfCanvas, as the existing list logic in
here is destined (sooner rather than later) to be merged into the newer
list CSS translation class.
Content needs to be on a new line if it contains slashes due to a bug in
older versions of webkit. E.g., the one used in the qt runtime tests.
See https://bugs.webkit.org/show_bug.cgi?id=35010

In addition, asking for the value of a content block that contains a
counter returns a strange counter string such as "counter(-879878e564)".
I can't find a bug report for this, but it only occurs inside the qt
runtime tests.
@kogmbh-ci
Copy link

Build succeeded.
Refer to this link for build results: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/1550/

*
* 2. joining commas (i.e., commas between strings) are removed completely (some browsers separate content parts with commas)
* 3. no whitespace trimming or normalization is performed
* 4. replace counter(.*) with the text "counter(...)". It seems qtruntimetests fail as the counters don't survive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: Which version of Qt and which platform? Here for me (Qt 4.8.5 on OpenSuse) qtruntimetests passes if I go to variant with original counter content. It is just dropping the , between identifier and list-style-type (e.g. counter(list, decimal) becomes counter(list decimal)), which BTW also Firefox (28.0) and Chromium (33.0.1750.152) (both OpenSUSE) do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://www.w3.org/TR/CSS21/syndata.html#counter actually specifies counter(<identifier>, <'list-style-type'>), strange that all drop the ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version used on the build server, and one I had on OSX (not sure the exact version). You can see the logs on the CI here: http://ci.kogmbh.com/jenkins/job/WebODF-PullReq/1499/consoleFull by searching for: counter(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Just for simplicity)

<span>Running <span style='color:blue;cursor:pointer' onclick='runTest("ListStyleToCssTests","numberedListPrefixes")'>numberedListPrefixes</span></span>
t.actualContent should be [a b] counter(list, decimal) []. Was [a b] counter(2.33059e-310) [].
t.actualContent should be ['] counter(list, decimal) []. Was ['] counter(2.33059e-310) [].
t.actualContent should be ["] counter(list, decimal) []. Was ["] counter(2.33059e-310) [].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my own hacked-up parsing logic doing that :). I made it do the proper tokenizing in 2c0f8a7, and then "unfixed" it in c9aadd8 as it re-simplified the logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, CI might only have QtWebKit of Qt 4.8.5 (due to being self-compiled there and not from packages if I saw correcty), and not the newer https://gitorious.org/webkit/qtwebkit-23 (like most Linux distris now do). And same for the OSX version. And our build requirements do not check fo that. I see.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, if those fixes are only done due to a pretty old webkit in normal Qt installations, which is nowhere else used in what we support, I propose to require the newer QtWebKit 2.3...
But that can/should be done in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my own hacked-up parsing logic doing that :).

"that" is what? That the , disappears? Cannot yet see where that would be done...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was meaning it's normalizeCSSContent stripping the comma out. Check the difference in this function between commit 2c0f8a7 and c9aadd8 for hints. Long story short, the first commit treats a ( as the start of a string region.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, in the test only. Hm, why do I continue to ignore the nice description in the API dox there :(
Okay.

@kossebau
Copy link
Contributor

In general seems fine and improves things without regression, good work, so can be merged. Please ship :)

peitschie added a commit that referenced this pull request Apr 30, 2014
Escape list prefix, suffix and bullet chars in the CSS rules
@peitschie peitschie merged commit 70031cf into webodf:master Apr 30, 2014
@peitschie
Copy link
Contributor Author

As per usual, thanks for the careful oversight :)

@peitschie peitschie deleted the css-injection branch April 30, 2014 13:29
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 this pull request may close these issues.

3 participants