Opened 7 years ago

Closed 4 years ago

#10625 closed Bug (fixed)

Ewkt regexp incorrectly escaped in GeoDjango admin javascript

Reported by: timlinux Owned by: springmeyer
Component: GIS Version: master
Severity: Normal Keywords: regexp ewkt
Cc: chris.chamberlin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



in the regexp on line 3 is incorrectly escaped, causing conversion from ewkt to wkt to fail for me. I fixed it by changing:

new RegExp("^SRID=\d+;(.+)", "i");


new RegExp("^SRID=\\d+;(.+)", "i");

After which it correctly works for me. Would be great if you can apply this fix.



Attachments (1)

10625.patch (1.0 KB) - added by aaugustin 4 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by Alex

  • milestone changed from 1.1 beta to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by jbronn

What browser version, please?

comment:3 Changed 7 years ago by psmith

I wasn't able to reproduce this. I tried:

  • Linux:
    • FF 3.0.9
    • Opera 9.6
  • Win XP:
    • FF 3.0.10
    • Opera 9.64
    • IE 6.0.x

Suggest this be punted to 1.2 since we don't have a user-agent yet of the reported bug.

comment:4 Changed 7 years ago by Alex

  • Resolution set to worksforme
  • Status changed from new to closed

Paul tried half a dozen browsers and we have no new information from the reported, marking as worksforme.

comment:5 Changed 5 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

comment:6 Changed 4 years ago by chris.chamberlin@…

  • Cc chris.chamberlin@… added
  • Easy pickings unset
  • Resolution worksforme deleted
  • Severity set to Normal
  • Status changed from closed to reopened
  • Summary changed from Ewkt regexp incorrectly escaped to Ewkt regexp incorrectly escaped in GeoDjango admin javascript
  • Type set to Bug
  • UI/UX set

I'm seeing this bug in Chrome 17.0.963.56; it's fairly simple to verify that the regexp does not match as designed, using a Javascript console:

> var brokenre = new RegExp("^SRID=\d+;(.+)", "i");
> brokenre.exec('SRID=4326;POINT(1 1)')
> var fixedre = new RegExp("^SRID=\\d+;(.+)", "i");
> fixedre.exec('SRID=4326;POINT(1 1)')
["SRID=4326;POINT(1 1)", "POINT(1 1)"]

It does not usually appear because the read_wkt() function is generally only called on startup, when the WKT textarea does not contain the EWKT format (with the SRID=4326; string that we're trying to strip).

It does appear, however, if read_wkt() is called again later; I wanted to be able to edit geometries by using either the map or the WKT textbox, so I added a JQuery change handler in an template as follows, mostly using code adapted from the openlayers.js file. In my GeoModelAdmin, I set map_template = "/path/to/my/template" and display_wkt=True.

{% extends "gis/admin/openlayers.html" %}

{% block init_function %}
{{ block.super }}
(function($) {
    $('.vWKTField').height('3em').change(function(e) {
        var wkt =
        if (wkt){
            // After reading into geometry, immediately write back to
            // WKT <textarea> as EWKT (so that SRID is included).
            var admin_geom = {{ module }}.read_wkt(wkt);
            {{ module }}.deleteFeatures();
            {{ module }}.write_wkt(admin_geom);
            if ({{ module }}.is_collection){
                // If geometry collection, add each component individually so they may be
                // edited individually.
                for (var i = 0; i < {{ module }}.num_geom; i++){
                {{ module }}.layers.vector.addFeatures([new OpenLayers.Feature.Vector(admin_geom.geometry.components[i].clone())]);
            } else {
                {{ module }}.layers.vector.addFeatures([admin_geom]);
            // Zooming to the bounds.
            {{ module }}.map.zoomToExtent(admin_geom.geometry.getBounds());
            if ({{ module }}.is_point){
                {{ module }}.map.zoomTo({{ point_zoom }});
{% endblock init_function %}

comment:7 Changed 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Accepted
  • UI/UX unset

From code inspection, I'm convinced that the bug report is correct. All other JavaScript regexps use double backslashes.

Changed 4 years ago by aaugustin

comment:8 Changed 4 years ago by aaugustin

I'm attaching the patch (1 char). I don't have time to test this now.

comment:9 Changed 4 years ago by claudep

  • Resolution set to fixed
  • Status changed from reopened to closed

In [17760]:

Fixed #10625 -- Fixed a Javascript regex in openlayers.js. Thanks timlinux for the report and Aymeric Augustin for the patch.

Note: See TracTickets for help on using tickets.
Back to Top