Modify

Opened 6 years ago

Last modified 4 years ago

#7614 reopened defect

preferences.xml: invalid XML character / reference to entity

Reported by: anonymous Owned by: team
Priority: normal Milestone:
Component: Core Version:
Keywords: Cc:

Description (last modified by simon04)

If there is a (U+2642) or & in the preferences.xml, an error occures:
"Preferences file had errors.
Making backup of old one to /home/test/.josm/preferences.xml.bak and creating a new default preference file."

This are allowed characters in filenames (for example ext3 filesystem).

Example 1:

<list key='file-open.history'>
    <entry value='/test/Blabla/123.gpx'/>
(...)
Repository Root: http://josm.openstreetmap.de/svn
Build-Date: 2012-04-14 14:26:11
Last Changed Author: simon04
Revision: 5181
Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
URL: http://josm.openstreetmap.de/svn/trunk
Last Changed Date: 2012-04-14 12:01:16 +0200 (Sat, 14 Apr 2012)
Last Changed Rev: 5181

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}" and element is "1a".
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:944)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:436)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:253)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
        at com.sun.org.apache.xerces.internal.jaxp.validation.StreamValidatorHelper.validate(StreamValidatorHelper.java:147)
        at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:116)
        at javax.xml.validation.Validator.validate(Validator.java:124)
        at org.openstreetmap.josm.data.Preferences.validateXML(Preferences.java:1476)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:621)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:583)
        at org.openstreetmap.josm.data.Preferences.init(Preferences.java:720)
        at org.openstreetmap.josm.gui.MainApplication.main(MainApplication.java:194)

Example 2:

  <list key='file-open.history'>
    <entry value='/test/Bla&bla/123.gpx'/>
(...)
Repository Root: http://josm.openstreetmap.de/svn
Build-Date: 2012-04-14 14:26:11
Last Changed Author: simon04
Revision: 5181
Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
URL: http://josm.openstreetmap.de/svn/trunk
Last Changed Date: 2012-04-14 12:01:16 +0200 (Sat, 14 Apr 2012)
Last Changed Rev: 5181

org.xml.sax.SAXParseException: The reference to entity "bla" must end with the ';' delimiter.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:845)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:436)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:253)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
        at com.sun.org.apache.xerces.internal.jaxp.validation.StreamValidatorHelper.validate(StreamValidatorHelper.java:147)
        at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:116)
        at javax.xml.validation.Validator.validate(Validator.java:124)
        at org.openstreetmap.josm.data.Preferences.validateXML(Preferences.java:1476)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:621)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:583)
        at org.openstreetmap.josm.data.Preferences.init(Preferences.java:720)
        at org.openstreetmap.josm.gui.MainApplication.main(MainApplication.java:194)

Attachments (2)

bug_test.sh (386 bytes) - added by anonymous 6 years ago.
7614.patch (1.7 KB) - added by simon04 6 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 6 years ago by simon04

Description: modified (diff)

comment:2 Changed 6 years ago by simon04

Resolution: worksforme
Status: newclosed

I cannot reproduce: When saving &.osm from JOSM, <entry value='/tmp/&amp;.osm'/> is written to the preference file. U+2642 works, too.

When editing the preference file by hand, make sure to correctly escape characters like &.

Last edited 6 years ago by simon04 (previous) (diff)

Changed 6 years ago by anonymous

Attachment: bug_test.sh added

comment:3 Changed 6 years ago by anonymous

Resolution: worksforme
Status: closedreopened

Ok, here is a real world example.

Create the test dir and test file (execute the attached bash script).
Then open the created test GPX-file, close JOSM.
You will find the following lines in preferences.xml:

  <list key='file-open.history'>
    <entry value='/tmp/DIR&#xD;TEST/test.gpx'/>

Start JOSM, an error occures:

Preferences file had errors. Making backup of old one to /home/test/.josm/preferences.xml.bak and creating a new default preference file.

Now you can reproduce.

By the way:
HAL creates this funny mountpoints, if a USB mass storage device (GPS device or smartphone) sends a identifier, containing this characters.

Log:

Repository Root: http://josm.openstreetmap.de/svn
Build-Date: 2012-04-14 14:26:11
Last Changed Author: simon04
Revision: 5181
Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
URL: http://josm.openstreetmap.de/svn/trunk
Last Changed Date: 2012-04-14 12:01:16 +0200 (Sat, 14 Apr 2012)
Last Changed Rev: 5181

org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}" and element is "1a".
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1391)
        at com.sun.org.apache.xerces.internal.impl.XMLScanner.scanAttributeValue(XMLScanner.java:944)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanAttribute(XMLNSDocumentScannerImpl.java:436)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:253)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2732)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:741)
        at com.sun.org.apache.xerces.internal.jaxp.validation.StreamValidatorHelper.validate(StreamValidatorHelper.java:147)
        at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:116)
        at javax.xml.validation.Validator.validate(Validator.java:124)
        at org.openstreetmap.josm.data.Preferences.validateXML(Preferences.java:1476)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:621)
        at org.openstreetmap.josm.data.Preferences.load(Preferences.java:583)
        at org.openstreetmap.josm.data.Preferences.init(Preferences.java:720)
        at org.openstreetmap.josm.gui.MainApplication.main(MainApplication.java:194)}}}

comment:4 Changed 6 years ago by simon04

According to http://www.w3.org/TR/xml/#charsets, U+001A is not a valid XML character. For that reason, Xerces refuses to parse this one – escaping as &#26; or &#x1A; does not help. Not sure how to fix this.

http://lists.xml.org/archives/xml-dev/201003/msg00080.html discusses the same issue. I think, we don't want to implement the work-around …

Last edited 6 years ago by simon04 (previous) (diff)

comment:5 Changed 6 years ago by stoecker

Minimum would be not to create invalid files...

Changed 6 years ago by simon04

Attachment: 7614.patch added

comment:6 Changed 6 years ago by simon04

I attached a possible fix. Avoids invalid XML file. In this case, the file entry in "Open Recent" does not exist.

comment:7 Changed 6 years ago by bastiK

#x1A is valid in XML 1.1: http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets, but must be escaped as entity.

Not sure if XML 1.1 is supported by Java, changing the header in preferences.xml makes JOSM stall without any output.

comment:8 Changed 6 years ago by Don-vip

#7648 is related.

comment:9 in reply to:  7 Changed 4 years ago by Don-vip

Replying to bastiK:

Not sure if XML 1.1 is supported by Java.

It seems to be, at least there's a basic support. However, we also need XSD 1.1, which became a W3C recommendation in April 2012... I don't think we'll see it in Java SE before Java 9 at least.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as reopened The owner will remain team.
as The resolution will be set.
to The owner will be changed from team to the specified user.
The owner will change to anonymous
as duplicate The resolution will be set to duplicate.The specified ticket will be cross-referenced with this ticket

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.