Modify

Opened 10 months ago

Closed 10 months ago

Last modified 10 months 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 (7)

comment:2 by stoecker, 10 months ago

Milestone: 25.01

comment:3 by stoecker, 10 months 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, 10 months ago

Resolution: fixed
Status: newclosed

In 19288/josm:

add missing escape characters to mapcss parser, fix #24095

comment:5 by goodidea, 10 months ago

Great! Thank you for the fast fix!!! I hope the next JOSM Version comes soon ...

comment:6 by stoecker, 10 months ago

Simply use josm-latest. 😺

comment:7 by goodidea, 10 months ago

josm-latest: thanks for the hint! I forgot, that it's easy to launch the latest build ... Haven't used it for a long time.

I first tried to start a JOSM jar of the 19290 build with the terminal in macOS (and had Azul JDK 17.0.14 installed!) – but not so easy, because it seems necessary to add further parameters like --add-exports=java.base/sun.security.action=ALL-UNNAMED and others. Then I found the right ones in the JNLPs and in the end it worked. But it took me some time to figure it out. The instructions on https://josm.openstreetmap.de/wiki/Download#Java didn't really help with everything. It worked with (not sure if ALL the parameters are necessary):

java --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.nio=ALL-UNNAMED --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED --add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED --add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED -jar josm-latest.jar

But with the josm-latest.jnlp it's easier … and there is the nice JAVA console from OpenWebStart with coloured text ... But then I directly fell into the next trap: I ​​renamed it to JOSM latest Webstart (pre-release development version, not fully tested, with JAVA 11+).jnlp, which immediately caused an error with OpenWebStart because of the + character. Also took some time to find that out ... See https://github.com/karakun/OpenWebStart/issues/599. Bad luck – and always pitfalls with JAVA. But now I know what to look out for (and what I should not do).

And according to the roadmap, the next tested, stable version should come in some hours (milestone 25.01), if I understand correctly. Very nice!

Last edited 10 months ago by goodidea (previous) (diff)

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.