Changeset 7124 in josm


Ignore:
Timestamp:
2014-05-14T13:47:05+02:00 (6 years ago)
Author:
simon04
Message:

MapCSS parsing: warn on unknown base selectors

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r7110 r7124  
    1010import java.io.InputStream;
    1111import java.nio.charset.StandardCharsets;
     12import java.text.MessageFormat;
    1213import java.util.ArrayList;
    1314import java.util.List;
     
    126127            }
    127128            MapCSSRule optRule = new MapCSSRule(r.selector.optimizedBaseCheck(), r.declaration);
    128             switch (((GeneralSelector) selRightmost).getBase()) {
     129            final String base = ((GeneralSelector) selRightmost).getBase();
     130            switch (base) {
    129131                case "node":
    130132                    nodeRules.add(optRule);
     
    149151                case "canvas":
    150152                    canvasRules.add(r);
     153                default:
     154                    final RuntimeException e = new RuntimeException(MessageFormat.format("Unknown MapCSS base selector {0}", base));
     155                    Main.warn(tr("Failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage()));
     156                    Main.error(e);
     157                    logError(e);
    151158            }
    152159        }
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r7123 r7124  
    310310        assert !s1.matches(new Environment().withPrimitive(w))
    311311    }
     312
     313    @Test
     314    public void testInvalidBaseSelector() throws Exception {
     315        def css = new MapCSSStyleSource("invalid_base[key=value] {}")
     316        css.loadStyleSource()
     317        assert !css.getErrors().isEmpty()
     318        assert css.getErrors().iterator().next().toString().contains("Unknown MapCSS base selector invalid_base")
     319    }
    312320}
Note: See TracChangeset for help on using the changeset viewer.