Modify

Opened 9 years ago

Closed 9 years ago

#9674 closed enhancement (fixed)

Support for escaping special characters

Reported by: imagic Owned by: team
Priority: normal Milestone: 14.02
Component: Core mappaint Version: tested
Keywords: MapCSS, SVG Cc: imagic

Description

In order to use user-provided text within an embedded SVG I'll need to escape any special characters. Although I could do this using multiple calls to replace, I would prefer to have some dedicated "escape" function.

I suggest to add a function escape(text, scope): "text" should be the text that needs escaping and "scope" the scope of the text.

Example: escape("abc [ < def","SVG") -> "abc &#91; &lt; def"

Attachments (0)

Change History (5)

comment:1 Changed 9 years ago by bastiK

Resolution: fixed
Status: newclosed

In 6805/josm:

fixed #9674 - Support for escaping special characters

comment:2 Changed 9 years ago by Don-vip

Milestone: 14.02

comment:3 Changed 9 years ago by imagic

Resolution: fixed
Status: closedreopened

Sorry to say, but it doesn't work. Using josm 6808 the following code will lead to a crash:

repeat-image: eval(concat("data:image/svg+xml,<svg height='70px'><g fill-opacity='0.3' stroke-opacity='0.3'><text x='0' y='50' font-size='50' fill='white' stroke='blue'>",URL_encode("Roma (A1) <E26> [IT]"),"</text></g></svg>"));

If I replace the character "<" by "." it doesn't crash, i.e. "Roma (A1) .E26> [IT]" works.

Repository Root: http://josm.openstreetmap.de/svn
Build-Date: 2014-02-04 02:35:03
Last Changed Author: Don-vip
Revision: 6808
Repository UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
URL: http://josm.openstreetmap.de/svn/trunk
Last Changed Date: 2014-02-04 00:21:44 +0100 (Tue, 04 Feb 2014)
Last Changed Rev: 6808

Identification: JOSM/1.5 (6808 de) Linux openSUSE 12.3 (x86_64)
Memory Usage: 155 MB / 1769 MB (52 MB allocated, but free)
Java version: 1.7.0_45, Oracle Corporation, Java HotSpot(TM) 64-Bit Server VM
VM arguments: [-DproxySet=xxx, -DproxyHost=xxx, -DproxyPort=xxx]
Dataset consistency test: No problems found

Plugin: buildings_tools (30057)
Plugin: imagery_offset_db (30218)
Plugin: openstreetbugs (30004)
Plugin: openvisible (29854)
Plugin: reverter (30258)
Plugin: turnrestrictions (30237)
Plugin: utilsplugin2 (30200)

java.lang.IllegalArgumentException: Parameter must not be null
	at org.openstreetmap.josm.tools.CheckParameterUtil.ensureParameterNotNull(CheckParameterUtil.java:90)
	at org.openstreetmap.josm.tools.ImageResource.<init>(ImageResource.java:37)
	at org.openstreetmap.josm.tools.ImageProvider.getIfAvailableDataUrl(ImageProvider.java:537)
	at org.openstreetmap.josm.tools.ImageProvider.getIfAvailableImpl(ImageProvider.java:402)
	at org.openstreetmap.josm.tools.ImageProvider.get(ImageProvider.java:303)
	at org.openstreetmap.josm.tools.ImageProvider.getInBackground(ImageProvider.java:343)
	at org.openstreetmap.josm.gui.mappaint.MapImage.getImage(MapImage.java:59)
	at org.openstreetmap.josm.gui.mappaint.RepeatImageElemStyle.paintPrimitive(RepeatImageElemStyle.java:56)
	at org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer$StyleCollector.drawAll(StyledMapRenderer.java:215)
	at org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer.render(StyledMapRenderer.java:1411)
	at org.openstreetmap.josm.gui.layer.OsmDataLayer.paint(OsmDataLayer.java:324)
	at org.openstreetmap.josm.gui.MapView.paintLayer(MapView.java:537)
	at org.openstreetmap.josm.gui.MapView.paint(MapView.java:608)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager$3.run(Unknown Source)
	at javax.swing.RepaintManager$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.access$1100(Unknown Source)
	at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$200(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Last edited 9 years ago by Don-vip (previous) (diff)

comment:4 Changed 9 years ago by bastiK

Ok, [6805] fixes a different problem. E.g.

icon-image: "data:image/svg+xml,<svg height='70px'><text x='0' y='50' font-size='50' fill='white' stroke='#efa3e4' style='line-height:125%;letter-spacing:normal;'>asdfasdf</text></svg>";

does not work, because the "%" sign is interpreted as percent encoding. This should be

icon-image: concat("data:image/svg+xml,", URL_encode("<svg height='70px'><text x='0' y='50' font-size='50' fill='white' stroke='#efa3e4' style='line-height:125%;letter-spacing:normal;'>asdfasdf</text></svg>"));

instead.

Now back to your issue. It is on a different level (special characters in xml). You can always use a <![CDATA[ ... ]]> block to protect this, but I'll add a xml escape function anyway.

comment:5 Changed 9 years ago by bastiK

Resolution: fixed
Status: reopenedclosed

In 6809/josm:

fixed #9674 - Support for escaping special characters

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.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.