Bug report #6812
Label direction symbol not quoted on save ?
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | Larry Shaffer | ||
Category: | Project Loading/Saving | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 15957 |
Description
The current topoviewer db_manager plugin ships templates for layer styles.
The templates are saved with "Save Style" so I know they were working before saving them.
On applying them I get an error "unrecognized character". The referenced line is this one:
<property key="labeling/leftDirectionSymbol" value="< "/>
I guess the problem is the unescaped '<' character.
That's line 80 of next_right.qml in the code base.
Indeed the same error occurs with the next_left.qml file, where
the '>' character is used instead.
So, haven't tested but I belive the problem is in style saving failing to
encode those characters.
I'm assigning to Larry as he's the one adding the custom direction character support.
History
#1 Updated by Larry Shaffer about 12 years ago
- Status changed from Open to Feedback
Hi Sandro,
Unfortunately, I can not replicate this issue. The new labeling settings are saved to the project XML file using the QgsMapLayer::writeCustomProperties method, which uses QDomElement::setAttribute method, which does encode the following xml special characters [ " < &
] (not including brackets), but does NOT encode [ ' >
].
I cleared all (left|right)DirectionSymbol
properties from a project file, then opened that project, turned on direction symbols (defaults to <
and >
) and saved the project. When I opened the project file in a text editor, the default properties were saved as:
<property key="labeling/leftDirectionSymbol" value="<"/> <property key="labeling/rightDirectionSymbol" value=">"/>
When saved to a style.qml and reloaded, I got no errors. I also got no errors when loading it using QgsMapLayer::loadNamedStyle
through Python. The right direction symbol of >
was not encoded because XML does not define it as a special character (only when used in the ]]>
sequence). Not sure why the apostrophe is not encoded.
I am not sure how your project file ended up with an unencoded <
, or how you got the error when loading a named .qml style for the >
character, since such operations also use the opposite QDomElement::attribute method, which should allow >
in the attribute value.
As a test, I added the following to QgsMapLayer:
QString QgsMapLayer::encodeCustomPropertyValue( const QString& txt ) const { QString tmp; for ( int i = 0; i < txt.size(); ++i ) { QChar c( txt.at( i ) ); switch ( c.unicode() ) { case '>': tmp += ">"; break; case '\\'': tmp += "'"; break; default: tmp += c; break; } } return tmp; } QString QgsMapLayer::decodeCustomPropertyValue( const QString& txt ) { QString tmp( txt ); tmp.replace( "'", "'" ); tmp.replace( ">", ">" ); return tmp; }
Then set left/right direction symbols to <'&"
and "&'>
which ended up as follows in the project file:
<property key="labeling/leftDirectionSymbol" value="<&apos;&""/> <property key="labeling/rightDirectionSymbol" value=""&&apos;&gt;"/>
Obviously, setAttribute
is double-encoding the ampersands. However, even though this loaded and worked fine (also upon saving and loading a .qml file), it should be unnecessary.
Could you please try deleting all (left|right)DirectionSymbol
properties from your project file, or just the layer in question, then set the symbols via the GUI and save the project and style for the layer? Then, try to reload the style for the layer via the GUI and Python and see if you get the errors again?
It could be a bug in the Qt version you are using.
#2 Updated by Sandro Santilli about 12 years ago
I couldn't trigger an error either, but I confirm I get unquoted brackets in the file.
Funny enough, it'sjust the rightDirectionSymbol, not the leftDirectionSymbol.
I added a space before the leftDirectionSymbol and after the rightDirectionSymbol, so maybe that part is significant.
Here's a grep in the project file (if hub won't mungle it):
$ grep DirectionSymbol ~/Desktop/proj_with_line_directions.qgs <property key="labeling/addDirectionSymbol" value="true"/> <property key="labeling/leftDirectionSymbol" value=" <"/> <property key="labeling/placeDirectionSymbol" value="0"/> <property key="labeling/reverseDirectionSymbol" value="false"/> <property key="labeling/rightDirectionSymbol" value="> "/> $ grep DirectionSymbol ~/Desktop/style_with_line_directions.qml <property key="labeling/addDirectionSymbol" value="true"/> <property key="labeling/leftDirectionSymbol" value=" <"/> <property key="labeling/placeDirectionSymbol" value="0"/> <property key="labeling/reverseDirectionSymbol" value="false"/> <property key="labeling/rightDirectionSymbol" value="> "/>
Note that when I reported the error I was getting it from a python plugin (db_manager) using layerloadNamedStyle, so the core may be more fault tolerant than the python XML parser maybe...
#3 Updated by Jürgen Fischer almost 12 years ago
- Status changed from Feedback to Open
#4 Updated by Sandro Santilli almost 12 years ago
- Resolution set to invalid
- Status changed from Open to Closed
I just tried again and can confirm that:
1. the "greater-than" symbol isn't quoted (also confirmed by Larry above)
2. only the "less-than" symbol triggers problems (not anymore user errors now, btw, but wrong XML interpretation)
Maybe the unencoded "less-than" symbol I entered manually. Will close this ticket as invalid.