Skip to content

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

Merged
tgregg merged 2 commits into
amazon-ion:masterfrom
radhika1314:quote-comment-operator-symbols
Dec 3, 2026
Merged

tgregg merged 2 commits into
amazon-ion:masterfrom
radhika1314:quote-comment-operator-symbols

Conversation

@radhika1314

Copy link
Copy Markdown
Contributor

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.
@radhika1314

Copy link
Copy Markdown
Contributor Author

any update?

@tgregg tgregg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix, thank you.

@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.39%. Comparing base (3c1b6b1) to head (8d5e2b1).
⚠️ Report is 173 commits behind head on master.

Files with missing lines Patch % Lines
.../com/amazon/ion/impl/_Private_IonTextAppender.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1171      +/-   ##
============================================
+ Coverage     67.23%   68.39%   +1.15%     
- Complexity     5484     5753     +269     
============================================
  Files           159      160       +1     
  Lines         23025    23518     +493     
  Branches       4126     4243     +117     
============================================
+ Hits          15481    16084     +603     
+ Misses         6262     6133     -129     
- Partials       1282     1301      +19     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tgregg
tgregg merged commit 4593c9d into amazon-ion:master Dec 3, 2026
27 of 37 checks passed
@toddjonker

Copy link
Copy Markdown
Contributor

Did this get corresponding additions to the ion-test suite? It's a significant defect so we should make sure we have testing for all implementations.

@toddjonker

Copy link
Copy Markdown
Contributor

Also, thanks for the fix, this was a great catch. (And an embarrassing bug)

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.

3 participants