Closed gurevi closed 9 years ago
@gurevi Good catch. Can confirm this with our parser + renderer as well. Will analyse this further by checking whether our DOM implementation is correct.
I have created a test-case here.
Will try to submit a unit-test later.
@hrj Cool, thanks.
Am learning Java by experimenting with jStyleParser so fixing this is most likely a little beyond me (for now) but glad to be able to contribute.
Thinking a little more about this, I can't recollect any specification about mandatory ordering of rules in this case.
However, it might be desirable to follow other User-agents, to reduce breakage.
I will wait for @radkovo to chip-in before digging further.
Hi, I mean @gurevi is right: the specification order is important and the latter specified value should win according to CSS specification: http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascading-order (item 4)
According to my tests, this bug does not occur in the latest release so it's probably caused by removing the priority strategy mechanism. But we can probably solve it without re-introducing the priority strategy, can we?
Oh, I completely mis-understood the issue then. I thought it was about the "order of classes" in the class attribute, rather than "order of rules" in the CSS because the title says: "Multiple classes for an element are in some cases improperly parsed".
I will analyse this and my priority related changes again.
Yes, the order of classes in the class attribute should not be important. But according to my tests, it is important in current jStyleParser, e.g. class="red green" works differently from class="green red". Thank you for taking a look on this.
Ah ok, I understand the issue better now. I have simplified the test-case to illustrate the problem more explicitly:
<html>
<head>
<style>
.red {font-size: 3em; color: red}
.blue{font-size: 1em; color: blue}
</style>
</head>
<body>
<div>Lorem ipsum <p class = "red blue"> This should be blue and in same font size as lorem ipsum</p></div>
<div>Lorem ipsum <p class = "blue red"> This should be blue and in same font size as lorem ipsum</p></div>
</body>
</html>
(Both the lines should render the same, but they are not the same with jStyleParser).
Yes, that's exactly the issue.
My experimental solution is in the ruleorder branch. It uses just a simple ordering in the Analyzer. @hrj Note that the order of style sheets passed to the Analyzer or DirectAnalyzer is now important as it corresponds to the CSS specification. However, they may be parsed in any order (in contrast to the original PriorityStrategy mechanism).
I have pushed another re-implementation to a new ruleorder_tuples branch.
@radkovo we have shipped this in gngr v0.3 and everything seems to be working fine. I guess this issue can be closed.
Great, thanks for info.
Just tested this and the parser is now working in situations it hadn't before. Thanks!
jStyleParser is a quite useful tool and am very happy that it exists. Have been playing with it and learning a lot. Thanks!
That said, I did notice an interesting and potentially significant bug.
It seems in some cases, jStyleParser evaluates CSS classes based on the order they are in and can miss if an element has multiple classes that modify the same property.
I researched it a bit and found that the order of the classes should not matter, rather it should go by which style rule comes later in the .css file.
For instance, let’s say you have
<div class ="red blue">
. The red CSS style has{color:red;}
and the blue has{color: blue;}
. As is, the div will always be parsed as being red because it came first.But the correct interpretation is, I believe, that it should be blue if the blue style rule comes later in the css.
This can be particularly significant with widths as shown below in a test case I came up with:
HTML file
CSS File
With this code, the potential bug can be seen in that both Firefox and Chrome interpret the width of the
<div class = "coltypea coltypeb">
element to be 10% as that definition comes later in the CSS.jStyleParser, however, seems to think that element has a width of 90%.
Not sure if it matters, but I am using TagSoup instead of NekoHTML to parse the HTML code.