[GRASS-dev] [GRASS GIS] #1791: gui modeler: cannot load file with r.mapcalc expression containing '&&' operator

#1791: gui modeler: cannot load file with r.mapcalc expression containing '&&'
operator
-------------------------+--------------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.3
Component: wxGUI | Version: unspecified
Keywords: modeler | Platform: Unspecified
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
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

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1791&gt;
GRASS GIS <http://grass.osgeo.org>

#1791: gui modeler: cannot load file with r.mapcalc expression containing '&&'
operator
-------------------------------+--------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: svn-trunk
Keywords: modeler r.mapcalc | Platform: Unspecified
      Cpu: Unspecified |
-------------------------------+--------------------------------------------
Changes (by mlennert):

  * keywords: modeler => modeler r.mapcalc
  * version: unspecified => svn-trunk
  * milestone: 6.4.3 => 7.0.0

Comment:

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1791#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#1791: gui modeler: cannot load file with r.mapcalc expression containing '&&'
operator
-------------------------------+--------------------------------------------
Reporter: mlennert | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: svn-trunk
Keywords: modeler r.mapcalc | Platform: Unspecified
      Cpu: Unspecified |
-------------------------------+--------------------------------------------

Comment(by 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.

For reference, I used [http://docs.python.org/2/library/xml.sax.utils.html
xml.sax.saxutils] instead of custom escape function. See also a
[http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
list of XML entities].

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1791#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#1791: gui modeler: cannot load file with r.mapcalc expression containing '&&'
operator
--------------------------+-------------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: svn-trunk
Resolution: fixed | Keywords: modeler r.mapcalc
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------
Changes (by mlennert):

  * status: new => closed
  * resolution: => fixed

Comment:

Replying to [comment:2 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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1791#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#1791: gui modeler: cannot load file with r.mapcalc expression containing '&&'
operator
--------------------------+-------------------------------------------------
  Reporter: mlennert | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.0
Component: wxGUI | Version: svn-trunk
Resolution: fixed | Keywords: modeler r.mapcalc
  Platform: Unspecified | Cpu: Unspecified
--------------------------+-------------------------------------------------

Comment(by wenzeslaus):

Replying to [comment:3 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
[http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
list at Wikipedia], other entities were already handled correctly (`<` and
`>`) or are probably not an issue (`"` and `'`) for our case.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/1791#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>