Modify

Opened 25 hours ago

Closed 13 hours ago

#24095 closed defect (fixed)

Unexpected MapCSS REGEX errors

Reported by: goodidea Owned by: team
Priority: normal Milestone: 25.01
Component: Core Version:
Keywords: Cc:

Description

I'm currently working on a more complex custom MapCSS (for traffic signs – but that's not relevant here), that makes extensive use of selectors with REGEX (regular expressions).

But some REGEX expressions did not work – and there were error messages in the JAVA console that I couldn't explain at all. And I had previously tested the REGEX expressions extensively, e.g. on https://regex101.com/, where you can also set JAVA as a REGEX flavor, and they seemed to be valid and error-free. I also got the desired results with test strings.

And according to the JOSM documentation (see https://josm.openstreetmap.de/wiki/Help/Styles/MapCSSImplementation#Conditionselector) the REGEX flavor, which is supported by JOSM, is the one of JAVA 11 – at least that's what the documentation says (https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html#sum).

After a lot of testing, I found out that this is probably the case, but that some special characters and predefined character classes etc. cause an error in JOSM, namely these (and I especially wanted to use \h for whitespace characters – which I have now replaced with \s, which works in contrast to \h – see below):

\t
\n
\r
\R
\f
\a
\e
\h
\H
\v
\V
\Q
\E

If you use this in a MapCSS, you will get an error message like this in the JAVA Console:

2025-01-23 19:27:56.578 SEVERE: Skipping to the next rule, because of an error: org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException: Encountered " "~" "~ "" at line 137, column 19.
Was expecting one of:
    "set" ...
    <IDENT> ...
    <UINT> ...
    <STRING> ...
    "(" ...
    <UFLOAT> ...
    <HEXCOLOR> ...
    <S> ...
    "=" ...
    "!" ...
    "+" ...
    "-" ...
    "/*" ...
    <S> ...
    "-" ...
    <UINT> ...
    "-" ...
    <UFLOAT> ...
    <UINT> ...
    <IDENT> ...
    "set" ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <STRING> ...
    <IDENT> ...
    "set" ...


These special characters, predefined character classes and boundary matchers, however, work without problems:

\d
\D
\s
\S
\w
\W
\b
\B
\A
\G
\z
\Z

Is this a bug in the MapCSS parser – or is the documentation of which REGEX expressions are supported “just” inadequate and should be clarified?

What steps will reproduce the problem?

Create a custom CSS with a rule like:

node[traffic_sign=~/^xxx\hxxx.*/] {
   text: auto;
}

... and add it to the JOSM map paint styles.

Additional system information:

Revision:19277
Build-Date:2025-01-04 02:30:34
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (19277 en) Mac OS X 10.14.6
OS Build number: Mac OS X 10.14.6 (18G9323)
Memory Usage: 998 MB / 4096 MB (453 MB allocated, but free)
Java version: 17.0.13+11-LTS, Azul Systems, Inc., OpenJDK 64-Bit Server VM
Look and Feel: com.apple.laf.AquaLookAndFeel

Last errors/warnings:

  • 03265.734 E: Skipping to the next rule, because of an error: org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException: Encountered " "~" "~ "" at line 137, column 19.

Attachments (0)

Change History (4)

comment:2 by stoecker, 25 hours ago

Milestone: 25.01

comment:3 by stoecker, 25 hours ago

Thanks for that detailed report. Fix should be easy now for someone not using his mobile to check new bugcreports. 😀

comment:4 by stoecker, 13 hours ago

Resolution: fixed
Status: newclosed

In 19288/josm:

add missing escape characters to mapcss parser, fix #24095

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.