Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#1791 closed defect (fixed)

gui modeler: cannot load file with r.mapcalc expression containing '&&' operator

Reported by: mlennert Owned by: grass-dev@…
Priority: normal Milestone: 7.0.0
Component: wxGUI Version: svn-trunk
Keywords: modeler r.mapcalc Cc:
CPU: Unspecified Platform: Unspecified

Description

I have a model in which I use r.mapcalculator with the '&&' operator:

<parameter name="formula">
    <value>if(A==0 && B&gt; 4, 1, A)</value>
</parameter>

After saving the model to a file, I cannot load it back into the modeler. Instead I get the following error:

self._parser.Parse(data, 0)
xml.parsers.expat
.
ExpatError
:
not well-formed (invalid token): line 46, column 32

Moritz

Change History (4)

comment:1 by mlennert, 11 years ago

Keywords: r.mapcalc added
Milestone: 6.4.37.0.0
Version: unspecifiedsvn-trunk

This ticket is still valid in grass7

Only the error message has changed:

Traceback (most recent call last):
  File
"/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64
-unknown-linux-gnu/etc/gui/wxpython/gmodeler/frame.py", line
391, in OnModelOpen

self.LoadModelFile(filename)
  File
"/data/home/mlennert/SRC/GRASS/grass_trunk/dist.x86_64
-unknown-linux-gnu/etc/gui/wxpython/gmodeler/frame.py", line
821, in LoadModelFile

(filename, e),
TypeError
:
coercing to Unicode: need string or buffer, ParseError found

Erasing the '&&' in the .gxm file allows to load it, but you then have to manually enter it again.

Moritz

comment:2 by wenzeslaus, 11 years ago

Thanks for reminding about this issue. It is actually trivial (at least I hope that I haven't overlooked something). Should be fixed for trunk in r58371.

I tested it but it would be better if you test it, too, XML can be tricky.

For reference, I used xml.sax.saxutils instead of custom escape function. See also a list of XML entities.

in reply to:  2 ; comment:3 by mlennert, 11 years ago

Resolution: fixed
Status: newclosed

Replying to wenzeslaus:

Thanks for reminding about this issue. It is actually trivial (at least I hope that I haven't overlooked something). Should be fixed for trunk in r58371.

I tested it but it would be better if you test it, too, XML can be tricky.

It works here when you create a new model file. One which already contains '&&' still cannot be loaded (which is logical as your change concerns writing the file), but I guess that this cannot be easily solved and that your solution is good enough. Any existing model files still have to be handled manually, but as soon as you save them again the issue is solved.

I'm closing the bug for now.

Thanks for the quick fix !

Moritz

in reply to:  3 comment:4 by wenzeslaus, 11 years ago

Replying to mlennert:

It works here when you create a new model file. One which already contains '&&' still cannot be loaded (which is logical as your change concerns writing the file), but I guess that this cannot be easily solved and that your solution is good enough. Any existing model files still have to be handled manually, but as soon as you save them again the issue is solved.

Yes of course, I forgot to mention. It now writes a well-formed XML and also reads well-formed XML (as before).

So, if you have existing .gxm file you need to load it with error and than fix the damaged expressions or other parameters, or you can open the .gxm in text editor and replace (probably all) occurrences of && by &amp;&amp;. Doing so, you will create a well-formed XML from your old XML (e.g. Gedit highlights && as invalid syntax). Example file part:

<task name="r.mapcalc">
    <parameter name="expression">
        <value>elevation &amp;&amp; aspect</value>
    </parameter>
</task>

Looking at the list at Wikipedia, other entities were already handled correctly (< and >) or are probably not an issue (" and ') for our case.

Note: See TracTickets for help on using tickets.