Changing hex value when it starts with letter
vanjavk opened this issue · 4 comments
Hello!
I don’t understand how you got the "\3" added, could you explain what you exactly did, please?
Hello!
I don’t understand how you got the "\3" added, could you explain what you exactly did, please?
Here is reproducible code that shows it:
using
tinycss2 1.1.0
https://gist.github.com/vanjavk/47c70e64e1481c461a06c52096368490
Hi!
When you change values, you have to also change the other attributes.
In this case, you have to set is_identifier
to False
for the Node containing 000000
and True
to the other one.
#000000
and #FFFFFF
are parsed into HashToken
. These token have a value
and a is_identifier
attribute.
is_identifier
is set to True
if the value is a valid identifier, which is the case of FFFFFF
but not of 000000
.
When you invert the value between the two HashToken, the value of is_identifier
is then wrong.
After, when serialize is called, it looks if the token is an identifier to know how to serialize it. As the is_identifier
is wrong, it doesn’t use the right serialization method and it serializes #000000
as it is a valid identifier. That’s why there is a \3
added.
Hi!
When you change values, you have to also change the other attributes.
In this case, you have to setis_identifier
toFalse
for the Node containing000000
andTrue
to the other one.
#000000
and#FFFFFF
are parsed intoHashToken
. These token have avalue
and ais_identifier
attribute.
is_identifier
is set toTrue
if the value is a valid identifier, which is the case ofFFFFFF
but not of000000
.
When you invert the value between the two HashToken, the value ofis_identifier
is then wrong.
After, when serialize is called, it looks if the token is an identifier to know how to serialize it. As theis_identifier
is wrong, it doesn’t use the right serialization method and it serializes#000000
as it is a valid identifier. That’s why there is a\3
added.
Well thank you for an explanation, I guess I now know how to make it work, however in the meantime I completely switched to cssutils.