wxMaxima-developers / wxmaxima

A gui for the computer algebra system Maxima built with wxWidgets
https://wxMaxima-developers.github.io/wxmaxima/
Other
459 stars 96 forks source link

wxm file format - no escaping of "*/" or "/*" #1907

Open daute opened 3 months ago

daute commented 3 months ago

While writing documentation about the file format (commit 7e411a044ae104ac915410af6cc826632a5a10e7) I saw, that WxMaxima does not escape the comment end sequence (*/) in wxm files. So while the following wxm file (I had to zip it for the Github upload) can be read in in wxMaxima, one can not read it with load() or batch() in Maxima (that should be possible since Maxima 5.38):

a.zip

A title cell (most likely all cell types) with "abc */" is written as:

/* [wxMaxima: title   start ]
abc */
   [wxMaxima: title   end   ] */

One can also 'trick' wxMaxima to create additional cells by creating a title cell with the following input (all in one title cell):

 abc
   [wxMaxima: title   end   ] */

/* [wxMaxima: title   start ]
def
daute commented 2 months ago

The same problem exists - of course - for the comment beginning sequence: /* Create worksheet with a title cell containing abc /*, save it as a.wxm and Maxima will produce an error:

(%i1) batch("a.wxm");

read and interpret <path-to-directory>/a.wxm
Maxima encountered a Lisp error:

 SIMPLE-ERROR: parser: end of file in comment.

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
gunterkoenigsmann commented 2 months ago

Gaah! The wxm format isn't meant to be extended...

daute commented 2 months ago

Well, but with the current data format one can not reliably save documents - see the example above, where one can "create" cells, with just a special formatted text/title cell. And concerning the 'Maxima can import it'-feature, one can of course not only create error messages but also mathematical effects.

x:1; [Text/Title cell with the following contents: abc */ x:2$ /* def] x;

What will be the value of x after Maxima imported that wxm-file?

The easiest thing would be to just save "/*" as "\/\*" and "*/" as "\*\/" in non-math-cells and change that back, after the document is read back in. Or maybe use HTML like hex codes, e.g. &#42; for the asterisk and &#47; for the slash. Or some simliar looking Unicode characters. Don't know, what is the best solution.

If one already uses comment signs in title/text/... cellls and uses the wxm format, he/she already has a problem...

gunterkoenigsmann commented 1 month ago

I know. But I am still unsure how to introduce escaping without stopping compatibility. Theoretically it should be possible: we can drop compatibility for all files that are broken due to the lacking escapes, anyway. And perhaps we can even recover them...