quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brendan O'Connor" <brend...@stanford.edu>
Subject Re: PSP escaping bug, and proposed fix
Date Wed, 21 Jul 2004 08:58:54 GMT
OK, I got the right flex and tested it.  Here's the correct patch for
psp_parser.l, as far as I can tell.  An example working is
http://piece.stanford.edu/~brendano/modpy/test.psp_

-Brendan

--- mod_python-3.1.3/src/psp_parser.l   2004-02-16 11:47:27.000000000 -0800
+++ mod_python-3.1.3-pspfix/src/psp_parser.l    2004-07-21 01:44:37.000000000 -0700
@@ -47,14 +47,14 @@
 %%

 \r\n|\n {
-    psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(\"\"\""));
+    psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(r\"\"\""));

     yyless(0);
     BEGIN TEXT;
 }

 . {
-    psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(\"\"\""));
+    psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(r\"\"\""));

     yyless(0);
     BEGIN TEXT;
@@ -87,11 +87,16 @@
 }

 <TEXT>. {
-    if (yytext[0] == '"') {
-        psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\\\""));
-    } else {
-        psp_string_appendc(&PSP_PG(pycode), yytext[0]);
-    }
+    /*   " no longer needs to be escaped */
+    psp_string_appendc(&PSP_PG(pycode), yytext[0]);
+}
+
+<TEXT>"\"\"\"" {
+    /* close python triplequoted string, put in a triple quote enclosed
+     * itself by single quotes, then restart the python triplequoted
+     * string. */
+    psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\"\"\" +'\"\"\"'+ r\"\"\""));
+
 }

 <TEXT><<EOF>> {
@@ -117,7 +122,7 @@
 <PYCODE>"%>" {

     if (PSP_PG(is_psp_echo)) {
-        psp_string_appendl(&PSP_PG(pycode), STATIC_STR("),0); req.write(\"\"\""));
+        psp_string_appendl(&PSP_PG(pycode), STATIC_STR("),0); req.write(r\"\"\""));
         PSP_PG(is_psp_echo) = 0;
     }
     else {
@@ -133,7 +138,7 @@
             PSP_PG(after_colon) = 0;
         }
         OUTPUT_WHITESPACE(&PSP_PG(whitespace));
-        psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(\"\"\""));
+        psp_string_appendl(&PSP_PG(pycode), STATIC_STR("req.write(r\"\"\""));
     }

     BEGIN TEXT;



Mime
View raw message