logological / gpp

GPP, a generic preprocessor
https://logological.org/gpp
GNU Lesser General Public License v3.0
192 stars 33 forks source link

Include is unintentionally stripping out escape chars #15

Closed zquintana closed 6 years ago

zquintana commented 7 years ago

Hey guys,

I appreciate the work your putting into this project. Recently on an old project I was trying to replace filepp with your gpp. Found a bug where escape strings are being stripped on include. As an example:

Included File Example:

<!-- include_me.html -->
<button onclick="DoSomething(\"tada\");" />

Main File:

<div>
#include "include_me.html"
</div>

The result:

<!-- include_me.html -->
<button onclick="DoSomething("tada");" />

Include works great, but it's stripping out the \ which then breaks the code. Tried looking through the code, but I'm not a C developer so my skills there are limited.

logological commented 6 years ago

Thanks for the bug report, and sorry for the delay in responding. Per the documentation, this is the expected behaviour when you use a mode that defines a quote character:

Furthermore, to avoid interference between the GPP syntax and the contents of the input file, a quote character is provided. The quote character can be used to prevent the interpretation of a macro call, comment, or string as anything but plain text. The quote character "protects" the following character, and always gets removed during evaluation. Two consecutive quote characters evaluate as a single quote character.

In the default mode, the backslash is the quote character, so when processing the input file, GPP changes all occurrences of \" to ". If you don't want it to do this, you should select a mode with a different quote character (or without any quote character at all), or else escape all your quote characters in your input file (i.e., changing all \ to \\).

kmpatel commented 5 years ago

With regards to escape chars in Javascript Javascript programs, "gpp -C" seems to work fine.