Skip to content

Quote operator symbols containing // or /* in the text writer - #1171

Open
radhika1314 wants to merge 1 commit into
amazon-ion:masterfrom
radhika1314:quote-comment-operator-symbols
Open

radhika1314 wants to merge 1 commit into
amazon-ion:masterfrom
radhika1314:quote-comment-operator-symbols

Conversation

@radhika1314

Copy link
Copy Markdown

Issue #, if available:

Description of changes:

IonTextUtils.symbolVariant and _Private_IonTextAppender.symbolNeedsQuoting treat any symbol made only of operator characters as an operator, so the text writer and Printer emit it unquoted inside an s-expression. //, /* and anything containing them (+/*, *//) are all operator characters, but the text reader starts a comment at / followed by / or *, so the written text no longer reads back as the same data.

  1. (// x) is what IonTextWriterBuilder and IonValue.toString() currently produce for a sexp of the symbols // and x. Reading it back drops x and everything else on the line.
  2. With /*, the comment runs until the next */, including one inside a later string. A pretty-printed {tags:(/*), role:user, note:"*/), role:admin, note:1 //"} reads back as {tags:(), role:admin, note:1}, so an application that writes untrusted symbol text can have other fields replaced on re-read.

Both helpers now quote the symbol when a / is directly followed by / or *. A lone / or */ still goes out unquoted. Added cases to TextTest.testSymbolNeedsQuoting and a round-trip test to TextWriterTest. Both fail without the change and pass with it, and ./gradlew build is green. The header rewrites in the touched files come from the spotless ratchet.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

A symbol made only of operator characters is written unquoted inside an
s-expression, but // and /* start a comment when the text is read back,
so the symbol and whatever follows it on re-read are lost or reparsed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant