Changeset 14810 in josm for trunk/src/org


Ignore:
Timestamp:
2019-02-24T23:31:36+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #17328 - visible html code in error message

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r14340 r14810  
    335335        String body = e.getErrorBody();
    336336        Object msg = null;
    337         if ("text/html".equals(e.getContentType()) && body != null && body.startsWith("<") && body.contains("<html>")) {
     337        if (e.isHtml() && body != null && body.startsWith("<") && body.contains("<html>")) {
    338338            msg = new HtmlPanel(body);
    339339        } else {
  • trunk/src/org/openstreetmap/josm/io/OsmApiException.java

    r14273 r14810  
    44
    55import org.openstreetmap.josm.tools.Logging;
     6import org.openstreetmap.josm.tools.Utils;
    67
    78/**
     
    3233        this.responseCode = responseCode;
    3334        this.errorHeader = errorHeader;
    34         this.errorBody = errorBody;
     35        this.errorBody = Utils.strip(errorBody);
    3536        this.accessedUrl = accessedUrl;
    3637        this.login = login;
    3738        this.contentType = contentType;
     39        checkHtmlBody();
    3840    }
    3941
     
    111113    public OsmApiException(String message, Throwable cause) {
    112114        super(message, cause);
     115    }
     116
     117    private void checkHtmlBody() {
     118        if (errorBody != null && errorBody.matches("^<.*>.*<.*>$")) {
     119            setContentType("text/html");
     120            if (!errorBody.contains("<html>")) {
     121                errorBody = "<html>" + errorBody + "</html>";
     122            }
     123        }
    113124    }
    114125
     
    268279        return contentType;
    269280    }
     281
     282    /**
     283     * Determines if the exception has {@code text/html} as content type.
     284     * @return {@code true} if the exception has {@code text/html} as content type.
     285     * @since xxx
     286     */
     287    public final boolean isHtml() {
     288        return "text/html".equals(contentType);
     289    }
    270290}
Note: See TracChangeset for help on using the changeset viewer.