Changeset 6787 in josm for trunk/src


Ignore:
Timestamp:
2014-01-30T18:02:53+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #9647 - filter invalid XML characters in changeset API responses

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/InvalidXmlCharacterFilter.java

    r6080 r6787  
    3636    }
    3737
     38    /**
     39     * Constructs a new {@code InvalidXmlCharacterFilter} for the given Reader.
     40     * @param reader The reader to filter
     41     */
    3842    public InvalidXmlCharacterFilter(Reader reader) {
    3943        this.reader = reader;
     
    6064        if (in < 0x20 && in >= 0 && INVALID_CHARS[in]) {
    6165            if (firstWarning) {
    62                 Main.warn("Invalid xml character encountered.");
     66                Main.warn("Invalid xml character encountered: '"+in+"'.");
    6367                firstWarning = false;
    6468            }
     
    6771        return in;
    6872    }
    69 
    7073}
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r6552 r6787  
    154154        }
    155155
    156         @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
     156        @Override
     157        public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    157158            if (qName.equals("osm")) {
    158159                if (atts == null) {
     
    215216            progressMonitor.beginTask("");
    216217            progressMonitor.indeterminateSubTask(tr("Parsing list of changesets..."));
    217             InputSource inputSource = new InputSource(new InputStreamReader(source, Utils.UTF_8));
     218            InputSource inputSource = new InputSource(new InvalidXmlCharacterFilter(new InputStreamReader(source, Utils.UTF_8)));
    218219            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, parser.new Parser());
    219220            return parser.getChangesets();
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r6716 r6787  
    8787        return getInputStreamRaw(urlStr, progressMonitor, null);
    8888    }
    89    
     89
    9090    /**
    9191     * Open a connection to the given url and return a reader on the input stream
     
    151151                    String errorHeader = activeConnection.getHeaderField("Error");
    152152                    StringBuilder errorBody = new StringBuilder();
    153                     try
    154                     {
    155                         InputStream i = FixEncoding(activeConnection.getErrorStream(), encoding);
     153                    try {
     154                        InputStream i = fixEncoding(activeConnection.getErrorStream(), encoding);
    156155                        if (i != null) {
    157156                            BufferedReader in = new BufferedReader(new InputStreamReader(i));
     
    170169                }
    171170
    172                 return FixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding);
     171                return fixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding);
    173172            } catch (OsmTransferException e) {
    174173                throw e;
     
    181180    }
    182181
    183     private InputStream FixEncoding(InputStream stream, String encoding) throws IOException
    184     {
     182    private InputStream fixEncoding(InputStream stream, String encoding) throws IOException {
    185183        if ("gzip".equalsIgnoreCase(encoding)) {
    186184            stream = new GZIPInputStream(stream);
    187         }
    188         else if ("deflate".equalsIgnoreCase(encoding)) {
     185        } else if ("deflate".equalsIgnoreCase(encoding)) {
    189186            stream = new InflaterInputStream(stream, new Inflater(true));
    190187        }
Note: See TracChangeset for help on using the changeset viewer.