Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/main/java/com/amazon/ion/impl/_Private_IonTextAppender.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl;

import static com.amazon.ion.impl._Private_IonConstants.MAX_LONG_TEXT_SIZE;
Expand Down Expand Up @@ -507,6 +494,13 @@ public static boolean symbolNeedsQuoting(CharSequence symbol,
if (!isOperatorPart(c)) {
return true;
}
// "//" and "/*" start a comment when read back.
if (c == '/' && ii + 1 < length) {
char next = symbol.charAt(ii + 1);
if (next == '/' || next == '*') {
return true;
}
}
}
return false;
}
Expand Down
24 changes: 9 additions & 15 deletions src/main/java/com/amazon/ion/util/IonTextUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.util;

import static com.amazon.ion.impl._Private_IonConstants.isHighSurrogate;
Expand Down Expand Up @@ -201,6 +188,13 @@ public static SymbolVariant symbolVariant(CharSequence symbol)
if (!isOperatorPart(c)) {
return SymbolVariant.QUOTED;
}
// "//" and "/*" start a comment when read back.
if (c == '/' && ii + 1 < length) {
char next = symbol.charAt(ii + 1);
if (next == '/' || next == '*') {
return SymbolVariant.QUOTED;
}
}
}
return SymbolVariant.OPERATOR;
}
Expand Down
39 changes: 24 additions & 15 deletions src/test/java/com/amazon/ion/impl/TextWriterTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.impl;

import static com.amazon.ion.SystemSymbols.ION_1_0;
Expand All @@ -26,6 +13,7 @@
import com.amazon.ion.IonReader;
import com.amazon.ion.IonSequence;
import com.amazon.ion.IonStruct;
import com.amazon.ion.IonType;
import com.amazon.ion.IonWriter;
import com.amazon.ion.SymbolTable;
import com.amazon.ion.SystemSymbols;
Expand Down Expand Up @@ -540,6 +528,27 @@ public void testWritingFloatNegativeInfinityToJson()
assertEquals("null", actual);
}

@Test
public void testOperatorSymbolThatStartsCommentIsQuoted()
throws Exception
{
iw = makeWriter();
iw.stepIn(IonType.SEXP);
iw.writeSymbol("/");
iw.writeSymbol("//");
iw.writeSymbol("+/*");
iw.writeSymbol("x");
iw.stepOut();
iw.writeSymbol("y");

String actual = outputString();
assertEquals("(/ '//' '+/*' x) y", actual);

IonDatagram dg = system().getLoader().load(actual);
assertEquals(2, dg.size());
assertEquals(4, ((IonSequence) dg.get(0)).size());
}

@Test
public void testSuppressInitialIvm()
throws Exception
Expand Down
26 changes: 11 additions & 15 deletions src/test/java/com/amazon/ion/util/TextTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
/*
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion.util;

import com.amazon.ion.BlobTest;
Expand Down Expand Up @@ -61,6 +48,15 @@ public void testSymbolNeedsQuoting()
unquotedInSexp("!");
unquotedInSexp("<");
unquotedInSexp("<===");
unquotedInSexp("/");
unquotedInSexp("*/");

// These would start a comment if left unquoted.
quotedEverywhere("//");
quotedEverywhere("/*");
quotedEverywhere("+//");
quotedEverywhere("+/*");
quotedEverywhere("*//");

quotedEverywhere("<abc");
quotedEverywhere("<abc>");
Expand Down