Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-03-27 11:15:50 -0400
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2018-03-28 10:30:12 -0400
commitd284d75f3960247c324b2c9916256a2474eab432 (patch)
tree8c82f25cce279a55d93db73074681e1261400cb2 /src
parent67d0cd69eca701055b7b58d75b772730283a911d (diff)
downloadtame-d284d75f3960247c324b2c9916256a2474eab432.tar.gz
tame-d284d75f3960247c324b2c9916256a2474eab432.tar.bz2
tame-d284d75f3960247c324b2c9916256a2474eab432.zip
js compiler: Prevent octals in generated code
* src/current/compiler/js.xsl (compiler:js-number): New function to remove leading zeroes. (compile)[lv:const]: Use it. * src/current/compiler/js-calc.xsl (compile-calc)[c:const]: Use it.
Diffstat (limited to 'src')
-rw-r--r--src/current/compiler/js-calc.xsl3
-rw-r--r--src/current/compiler/js.xsl27
2 files changed, 26 insertions, 4 deletions
diff --git a/src/current/compiler/js-calc.xsl b/src/current/compiler/js-calc.xsl
index 072f903..2fff67d 100644
--- a/src/current/compiler/js-calc.xsl
+++ b/src/current/compiler/js-calc.xsl
@@ -40,6 +40,7 @@
xmlns:c="http://www.lovullo.com/calc"
xmlns:lv="http://www.lovullo.com/rater"
xmlns:preproc="http://www.lovullo.com/rater/preproc"
+ xmlns:compiler="http://www.lovullo.com/rater/compiler"
xmlns:calc-compiler="http://www.lovullo.com/calc/compiler">
@@ -453,7 +454,7 @@
-->
<template match="c:const" mode="compile-calc">
<!-- assumed to be numeric -->
- <value-of select="@value" />
+ <sequence select="compiler:js-number( @value )" />
</template>
diff --git a/src/current/compiler/js.xsl b/src/current/compiler/js.xsl
index 8bf9093..78afb0c 100644
--- a/src/current/compiler/js.xsl
+++ b/src/current/compiler/js.xsl
@@ -444,7 +444,7 @@
<text>, </text>
</if>
- <value-of select="." />
+ <value-of select="compiler:js-number( . )" />
</for-each>
<text> ]</text>
</for-each>
@@ -455,7 +455,7 @@
<text>, </text>
</if>
- <value-of select="." />
+ <value-of select="compiler:js-number( . )" />
</for-each>
<text> ]; </text>
@@ -470,7 +470,7 @@
<text>consts['</text>
<value-of select="@name" />
<text>'] = </text>
- <value-of select="@value" />
+ <value-of select="compiler:js-number( @value )" />
<text>;</text>
</template>
@@ -530,6 +530,27 @@
<!--
+ Format JS numbers such that they won't be misinterpreted as octal (if they
+ have leading zeroes)
+-->
+<function name="compiler:js-number" as="xs:string?">
+ <param name="src" as="xs:string?" />
+
+ <variable name="norm" as="xs:string?"
+ select="normalize-space( $src )" />
+
+ <!-- note that this will make 0 into an empty string! -->
+ <variable name="stripped" as="xs:string"
+ select="replace( $norm, '^0+', '' )" />
+
+ <sequence select="if ( $stripped = '' ) then
+ $norm
+ else
+ $stripped" />
+</function>
+
+
+<!--
Generate code to perform a classification
Based on the criteria provided by the classification, generate and store the