Skip to content

Commit

Permalink
Fix issue with only "-" and whitespace in element
Browse files Browse the repository at this point in the history
Fixes: #2198

If there is a single "-" or it is only accompanied by whitespace, then
it wouldn't get escaped as it was detected as as a number. This would
produce invalid JSON.
This makes the numbers part ignore such and thus ensures it gets escaped
as text.

There might be other corner cases related to number parsing, this should be investigated.
  • Loading branch information
dm8tbr committed May 25, 2015
1 parent 0b1ac3e commit 56bbc0d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion web/xml2json.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
<!-- number (no support for javascript mantissa) -->
<xsl:template match="text()[not(string(number())='NaN' or
(starts-with(.,'0' ) and . != '0' and not(starts-with(.,'0.' ))) or
(starts-with(.,'-0' ) and . != '-0' and not(starts-with(.,'-0.' ))))]">
(starts-with(.,'-0' ) and . != '-0' and not(starts-with(.,'-0.' )))) and
not(substring(normalize-space(.), string-length(normalize-space(.))) = '-')]">
<xsl:choose>
<xsl:when test="starts-with(.,'.')">
<xsl:value-of select="concat('0',.)"/>
Expand Down

0 comments on commit 56bbc0d

Please sign in to comment.