Project

Profile

Help

Bug #5387

closed

Adaptive serialization only escapes the first quotation mark in a string

Added by Michael Kay about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2022-03-12
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
2, Trunk
Fix Committed on JS Branch:
2, Trunk
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

The command xslt3ee -xp:codepoints-to-string((34,34)) produces the output

"""""

(five double quotation marks).

The result of the expression itself appears to be correct (wrapping a call of string-to-codepoints() around the expression delivers a result of 34 34) but the way the result is displayed is rather strange.

Actions #1

Updated by Michael Kay about 2 years ago

The code for the adaptive serialization method (Serialize.js line 1887) is doing

w.write('"' + applyCharMap(item.toString().replace(/"/, '""')) + '"');

The spec says: *An instance of xs:string, xs:untypedAtomic or xs:anyURI is serialized by enclosing the value in double quotation marks and doubling any quotes within the value; or optionally by enclosing the value in apostrophes and doubling any apostrophes within the value. *

The code is incorrect because replace() only replaces the first instance. If we fix it to do a global replace, we get a correct answer of six double-quotation marks (equally unreadable, but correct). But a smarter solution is to use single quotes as the delimiter if the string contains double quotes.

The use case in question is actually displaying a string that contains JSON. This is probably not uncommon. Since JSON is likely to contain double-quotes, it's worth the effort to use single-quotes as the delimiter in this case.

Actions #2

Updated by Michael Kay about 2 years ago

Added QT3 test case Serialization-adaptive-85

Actions #3

Updated by Michael Kay about 2 years ago

  • Status changed from New to Resolved

Fixed:

(a) the replace is now global

(b) we use single quotes as delimiter if the string contains double-quotes

Actions #4

Updated by Michael Kay about 2 years ago

  • Subject changed from Strange display of "" in command line output to Adaptive serialization only escapes the first quotation mark in a string
  • Applies to JS Branch 2, Trunk added
  • Fix Committed on JS Branch 2, Trunk added
Actions #5

Updated by Debbie Lockett almost 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to SaxonJS 2.4

Bug fix applied in the SaxonJS 2.4 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page