Ticket #5083: validator-patch.patch

File validator-patch.patch, 2.8 KB (added by bilbo, 16 years ago)

Check for characters <0x20 in validator

  • src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java

     
    140140    protected static int PAINT             = 1207;
    141141    protected static int LONG_VALUE        = 1208;
    142142    protected static int LONG_KEY          = 1209;
     143    protected static int LOW_CHAR_VALUE    = 1210;
     144    protected static int LOW_CHAR_KEY      = 1211;
    143145    /** 1250 and up is used by tagcheck */
    144146
    145147    /** List of sources for spellcheck data */
     
    390392    }
    391393
    392394    /**
     395     * Checks given string (key or value) if it contains characters with code below 0x20 (either newline or some other special characters)
     396     * @param s string to check
     397     */
     398    private boolean containsLow(String s) {
     399        if (s==null) return false;
     400        for(int i=0;i<s.length();i++) {
     401            if (s.charAt(i)<0x20) return true;
     402        }
     403        return false;
     404    }
     405
     406    /**
    393407     * Checks the primitive properties
    394408     * @param p The primitive to check
    395409     */
     
    473487            String s = marktr("Key ''{0}'' invalid.");
    474488            String key = prop.getKey();
    475489            String value = prop.getValue();
     490            if( checkValues && (containsLow(value)) && !withErrors.contains(p, "ICV"))
     491            {
     492                errors.add( new TestError(this, Severity.WARNING, tr("Tag value contains character with code less than 0x20"),
     493                        tr(s, key), MessageFormat.format(s, key), LOW_CHAR_VALUE, p) );
     494                withErrors.add(p, "ICV");
     495            }
     496            if( checkKeys && (containsLow(key)) && !withErrors.contains(p, "ICK"))
     497            {
     498                errors.add( new TestError(this, Severity.WARNING, tr("Tag key contains character with code less than 0x20"),
     499                        tr(s, key), MessageFormat.format(s, key), LOW_CHAR_KEY, p) );
     500                withErrors.add(p, "ICK");
     501            }
    476502            if( checkValues && (value!=null && value.length() > 255) && !withErrors.contains(p, "LV"))
    477503            {
    478504                errors.add( new TestError(this, Severity.ERROR, tr("Tag value longer than allowed"),
    479505                        tr(s, key), MessageFormat.format(s, key), LONG_VALUE, p) );
    480506                withErrors.add(p, "LV");
    481507            }
    482             if( checkKeys && (value!=null && key.length() > 255) && !withErrors.contains(p, "LK"))
     508            if( checkKeys && (key!=null && key.length() > 255) && !withErrors.contains(p, "LK"))
    483509            {
    484510                errors.add( new TestError(this, Severity.ERROR, tr("Tag key longer than allowed"),
    485511                        tr(s, key), MessageFormat.format(s, key), LONG_KEY, p) );