trans-coord-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

trans-coord/gnun/server/gnun ChangeLog NEWS exp...


From: Ineiev
Subject: trans-coord/gnun/server/gnun ChangeLog NEWS exp...
Date: Sat, 4 Dec 2021 05:46:56 -0500 (EST)

CVSROOT:        /sources/trans-coord
Module name:    trans-coord
Changes by:     Ineiev <ineiev> 21/12/04 05:46:56

Modified files:
        gnun/server/gnun: ChangeLog NEWS expand-ssi.awk.in 
        gnun/server/gnun/tests/validate: 3.0.html 3.1.html 

Log message:
        Make variable expansions closer to Apache behavior,
        e.g. substitute var attribute in #set and #echo, allow the variable
        with empty name, output unassigned variables depending on the directive,
        process '\' more realistically.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/ChangeLog?cvsroot=trans-coord&r1=1.500&r2=1.501
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/NEWS?cvsroot=trans-coord&r1=1.154&r2=1.155
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/expand-ssi.awk.in?cvsroot=trans-coord&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/tests/validate/3.0.html?cvsroot=trans-coord&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/trans-coord/gnun/server/gnun/tests/validate/3.1.html?cvsroot=trans-coord&r1=1.1&r2=1.2

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/trans-coord/trans-coord/gnun/server/gnun/ChangeLog,v
retrieving revision 1.500
retrieving revision 1.501
diff -u -b -r1.500 -r1.501
--- ChangeLog   30 Nov 2021 07:55:14 -0000      1.500
+++ ChangeLog   4 Dec 2021 10:46:55 -0000       1.501
@@ -1,3 +1,13 @@
+2021-12-04  Pavel Kharitonov  <ineiev@gnu.org>
+
+       * expand-ssi.awk.in: Make variable expansions closer to Apache behavior,
+       e.g. substitute var attribute in #set and #echo, allow the variable
+       with empty name, output unassigned variables depending on the directive,
+       process '\' more realistically.
+       * tests/validate/3.0.html:
+       * tests/validate/3.1.html:
+       * NEWS: Update.
+
 2021-11-30  Pavel Kharitonov  <ineiev@gnu.org>
 
        * expand-ssi.awk.in: Expand variables in 'include' directives.

Index: NEWS
===================================================================
RCS file: /sources/trans-coord/trans-coord/gnun/server/gnun/NEWS,v
retrieving revision 1.154
retrieving revision 1.155
diff -u -b -r1.154 -r1.155
--- NEWS        30 Nov 2021 07:55:14 -0000      1.154
+++ NEWS        4 Dec 2021 10:46:55 -0000       1.155
@@ -2,9 +2,12 @@
 
 * Changes in GNUnited Nations 1.2 (????-??-??)
 
-* When validating HTML, expand variables in 'include' directives.
-  Both Apache 2.2 and 2.4 work this way, though the documentation
-  isn't clear on that.
+* When validating HTML, SSI variable expansion is closer to Apache behavior.
+  The 'var' attribute of #set and #echo, 'file' / 'virtual' attribute
+  of #include are substituted.  Output of unassigned variables depends on
+  the directive (empty in #set, '(none)' in #echo, unexpanded in #if).
+  The variable with empty name is allowed.  Escape characters are processed 
more
+  realistically.
 
 * Changes in GNUnited Nations 1.1 (2021-09-10)
 

Index: expand-ssi.awk.in
===================================================================
RCS file: /sources/trans-coord/trans-coord/gnun/server/gnun/expand-ssi.awk.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- expand-ssi.awk.in   30 Nov 2021 07:55:14 -0000      1.3
+++ expand-ssi.awk.in   4 Dec 2021 10:46:55 -0000       1.4
@@ -21,7 +21,9 @@
 
 # The implementation is very limited,
 # e.g. `&&' and `||' in `if' expressions are not supported, as well as
-# many cases of quoting; CGI includes would be expanded in a wrong way.
+# many cases of quoting, multiple echo and assignments within a single
+# directive like <!--#set var="x" value="x" var="y" value="y" -->
+# also don't work, CGI includes would be expanded in a wrong way &c.
 
 # Fallback for awks who don't support RT.
 BEGIN { RT = "\n" }
@@ -29,29 +31,57 @@
 # Read whole file to `text'.
 { text = text $0 RT }
 
+# Return string representing an unassigned variable
+# depending on the value of the second argument.
+function unassigned_value(var, mode)
+{
+  if (mode == "none")
+    return "(none)"
+  if (mode == "name")
+    return "$" var
+  return ""
+}
+
 # Look for the variable first in the list of the named ones,
 # then in the numbered parts of the latest regex.
-function get_apache_var(var)
+function get_apache_var(var, unassigned)
 {
   if(var in apache_variables)
     return apache_variables[var]
   if(var in matched_array && var ~ /^[0-9]$/)
     return matched_array[var]
-  return val = ""
+  return unassigned_value(var, unassigned)
+}
+
+# Return the argument with escape characters removed.
+function unescape(str)
+{
+  gsub(/\\\\/, "\\", str)
+  gsub(/\\\$/, "$", str)
+  return str
 }
 
 # Substitute the variables in `str' with their values;
 # return the result.
-function expand_var_value(str,
-  vars, n, i, begin, end, rest, var, val)
+function expand_var_value(str, unassigned,
+  vars, n, i, begin, end, rest, var, val, prev)
 {
   n = split(str, vars, /\$/)
-  if(!n)
-    return ""
-  str = vars[1];
+  if(n)
+    str = vars[1]
+  str = unescape(str)
   for(i = 2; i <= n; i++)
     {
-      if(substr(vars[i], 1, 1) == "{")
+      prev = vars[i - 1]
+      gsub(/\\\\/, "", prev)
+      if (prev ~ /\\$/)
+        {
+          # The '$' is escaped; remove the escape character and don't expand
+          # the "variable".
+          begin = 0; end = -1
+          sub(/\\$/, "", str)
+        }
+      else if (substr(vars[i], 1, 1) == "{")
         {
           begin = 2; end = index(vars[i], "}"); rest = end + 1
         }
@@ -61,11 +91,11 @@
         }
       if(end <= begin)
         {
-          str = str "$" vars[i]; continue
+          str = str unescape(unassigned_value(vars[i], unassigned)); continue
         }
-      var = substr(vars[i],begin,end - begin)
-      val = get_apache_var(var)
-      str = str val (rest <= length(vars[i])? substr(vars[i], rest): "")
+      var = substr(vars[i], begin, end - begin)
+      val = get_apache_var(var, unassigned)
+      str = str val unescape(rest <= length(vars[i])? substr(vars[i], rest): 
"")
     }
   return str
 }
@@ -78,29 +108,17 @@
 
 # Process `<!--#set ... -->' directive.
 function assign_var(var, val,
-  i, q, n, expanded_val)
+  q)
 {
   # Extract variable name and value.
-  var = unquote(var)
+  var = expand_var_value(unquote(var), "name")
   q = substr(val, 1, 1)
   val = unquote(val)
   if(q == "\"")
     gsub(/\\"/, q, val)
   if(q == "'")
     gsub(/\\'/, q, val)
-  # Handle escaped `$'s when expanding val.
-  # Note: the unescaping is done in a different way when
-  # expanding `if' expressions in eval_expression().
-  n = split(val, arr, /\\\$/)
-  if(!n)
-    expanded_val = ""
-  else
-    {
-      expanded_val = expand_var_value(arr[1])
-      for(i = 2; i <= n; i++)
-        expanded_val = expanded_val "$" expand_var_value(arr[i])
-    }
-  apache_variables[var] = expanded_val
+  apache_variables[var] = expand_var_value(val, "name")
 }
 
 # URL encoding.
@@ -128,10 +146,10 @@
 function echo_var(str, arr,
   var, val, enc)
 {
-  if(length(arr[2]) > 2)
+  if(length(arr[2]) >= 2)
     {
       var = unquote(arr[2])
-      val = get_apache_var(var)
+      val = get_apache_var(expand_var_value(var), "none")
       if(1 in arr)
         {
           enc = arr[1]
@@ -332,14 +350,14 @@
 # `Set' directive: assign a variable.
       directive = substr(chunks[ch_i], 1, idx - 1)
       if(directive \
-~ /^set[ \t\r\n]+var=('.+'|".+")[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+-->/)
+~ /^set[ \t\r\n]+var=('.*'|".*")[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+-->/)
         {
           pattern[1] = directive
           sub(/^set[ \t\r\n]+var=/, "", pattern[1])
           sub(/[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+-->.*/,
               "", pattern[1])
           pattern[2] = directive
-          sub(/^set[ \t\r\n]+var=('.+'|".+")[ \t\r\n]+value=/, \
+          sub(/^set[ \t\r\n]+var=('.*'|".*")[ \t\r\n]+value=/, \
               "", pattern[2])
           sub(/[ \t\r\n]+-->.*/, "", pattern[2])
           assign_var(pattern[1], pattern[2])
@@ -349,14 +367,14 @@
         }
 # `Set' directive (different order of attributes).
       if(directive \
-~ /^set[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+var=('.+'|".+")[ \t\r\n]+-->/)
+~ /^set[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+var=('.*'|".*")[ \t\r\n]+-->/)
         {
           pattern[1] = directive
           sub(/^set[ \t\r\n]+value=/, "", pattern[1])
           sub(/[ \t\r\n]+var=('.*'|".*")[ \t\r\n]+-->.*/,
               "", pattern[1])
           pattern[2] = directive
-          sub(/^set[ \t\r\n]+value=('.+'|".+")[ \t\r\n]+var=/, \
+          sub(/^set[ \t\r\n]+value=('.*'|".*")[ \t\r\n]+var=/, \
               "", pattern[2])
           sub(/[ \t\r\n]+-->.*/, "", pattern[2])
           assign_var(pattern[2], pattern[1])
@@ -366,7 +384,7 @@
         }
 # `Echo' directive: output a variable.
       if(chunks[ch_i] \
-~ /^echo[ \t\r\n]+(encoding=("[^\"]*"|'[^']*')[ 
\t\r\n]+)?var=('[^']+'|"[^\"]+")[ \t\r\n]+-->/)
+~ /^echo[ \t\r\n]+(encoding=("[^\"]*"|'[^']*')[ 
\t\r\n]+)?var=('[^']*'|"[^\"]*")[ \t\r\n]+-->/)
         {
           if(chunks[ch_i] \
 ~ /^echo[ \t\r\n]+(encoding=("[^\"]*"|'[^']*')[ \t\r\n]+)/)

Index: tests/validate/3.0.html
===================================================================
RCS file: 
/sources/trans-coord/trans-coord/gnun/server/gnun/tests/validate/3.0.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- tests/validate/3.0.html     21 Feb 2014 15:49:56 -0000      1.1
+++ tests/validate/3.0.html     4 Dec 2021 10:46:55 -0000       1.2
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
-<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+<!-- Copyright (C) 2014, 2021 Free Software Foundation, Inc.
 
 This file is a part of GNUN testsuite.
 
@@ -21,9 +21,23 @@
 along with GNUnited Nations.  If not, see <http://www.gnu.org/licenses/>. -->
 <title>title - GNU Project - Free Software Foundation</title>
 </head>
-<body>
-<p><!--#echo var="a" --> <!--#echo var="b" --><!--#echo var="c" --></p>
-<!--#set var="a"
- value="changed test" --><p><!--#echo var="a" --> <!--#echo var="b" --></p>
+<body><!--#set var='a_bis' value="changed $a" --><!--#set var="head"
+ value="a" --><!--#set var="tail" value="bis" -->
+<p><!--#echo var="$head" --> <!--#echo var="b" --></p>
+<p><!--#echo var="${head}_$tail" --> <!--#echo var="b" --></p><!--#set 
var="ame"
+value="sc" --><!--#set var="e$ame"
+value="special characters: \$a \\$a \\\$b \\\\$b" -->
+<p><!--#echo var="esc" --></p><!--#set var="bis_"
+value="test unassigned variable" -->
+<p><!--#echo var="${tail}_" -->:
+<!--#echo var="$tail_" --> /
+<!--#echo var="c" --></p>
+<p>test empty name:
+<!--#echo var="" --> /
+<!--#set var="" value="assigned_value" --><!--#echo var="" --> /
+<!--#set var="c" value="${} " --><!--#echo var="c" -->/
+<!--#set var="c" value="$ /" --><!--#echo var="c" -->
+<!--#set var="${}" value="val" --><!--#echo var="assigned_value" --> /
+<!--#set var="$" value="val" --><!--#echo var="assigned_value" --></p>
 </body>
 </html>

Index: tests/validate/3.1.html
===================================================================
RCS file: 
/sources/trans-coord/trans-coord/gnun/server/gnun/tests/validate/3.1.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- tests/validate/3.1.html     21 Feb 2014 15:49:57 -0000      1.1
+++ tests/validate/3.1.html     4 Dec 2021 10:46:55 -0000       1.2
@@ -3,7 +3,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
-<!-- Copyright (C) 2014 Free Software Foundation, Inc.
+<!-- Copyright (C) 2014, 2021 Free Software Foundation, Inc.
 
 This file is a part of GNUN testsuite.
 
@@ -24,5 +24,16 @@
 <body>
 <p>test value</p>
 <p>changed test value</p>
+<p>special characters: $a \test \$b \\value</p>
+<p>test unassigned variable:
+(none) /
+(none)</p>
+<p>test empty name:
+(none) /
+assigned_value /
+${} /
+$ /
+(none) /
+(none)</p>
 </body>
 </html>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]