Changeset 7213 in josm for trunk


Ignore:
Timestamp:
2014-06-03T20:18:18+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10096 - robustness in MapCSS parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r7140 r7213  
    162162        }
    163163
     164        static final String POSSIBLE_THROWS = possibleThrows();
     165
     166        static final String possibleThrows() {
     167            StringBuffer sb = new StringBuffer();
     168            for (Severity s : Severity.values()) {
     169                if (sb.length() > 0) {
     170                    sb.append('/');
     171                }
     172                sb.append("throw")
     173                .append(s.name().charAt(0))
     174                .append(s.name().substring(1).toLowerCase());
     175            }
     176            return sb.toString();
     177        }
     178
    164179        static TagCheck ofMapCSSRule(final GroupedMapCSSRule rule) {
    165180            final TagCheck check = new TagCheck(rule);
     
    178193                            : null;
    179194                    if (ai.key.startsWith("throw")) {
    180                         final Severity severity = Severity.valueOf(ai.key.substring("throw".length()).toUpperCase());
    181                         check.errors.put(ai, severity);
     195                        try {
     196                            final Severity severity = Severity.valueOf(ai.key.substring("throw".length()).toUpperCase());
     197                            check.errors.put(ai, severity);
     198                        } catch (IllegalArgumentException e) {
     199                            Main.warn("Unsupported "+ai.key+" instruction. Allowed instructions are "+POSSIBLE_THROWS);
     200                        }
    182201                    } else if ("fixAdd".equals(ai.key)) {
    183202                        final PrimitiveToTag toTag = PrimitiveToTag.ofMapCSSObject(ai.val, false);
     
    203222            }
    204223            if (check.errors.isEmpty() && !containsSetClassExpression) {
    205                 throw new RuntimeException("No throwError/throwWarning/throwOther given! You should specify a validation error message for " + rule.selectors);
     224                throw new RuntimeException("No "+POSSIBLE_THROWS+" given! You should specify a validation error message for " + rule.selectors);
    206225            } else if (check.errors.size() > 1) {
    207                 throw new RuntimeException("More than one throwError/throwWarning/throwOther given! You should specify a single validation error message for " + rule.selectors);
     226                throw new RuntimeException("More than one "+POSSIBLE_THROWS+" given! You should specify a single validation error message for " + rule.selectors);
    208227            }
    209228            return check;
Note: See TracChangeset for help on using the changeset viewer.