Skip to content

Commit 01dbdbc

Browse files
committed
Fix Hoisted Text Span Symbol Table Bug
Fixes #1042
1 parent 7a89a85 commit 01dbdbc

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

src/main/java/com/amazon/ion/impl/IonReaderTextUserX.java

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright 2007-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License").
5-
* You may not use this file except in compliance with the License.
6-
* A copy of the License is located at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* or in the "license" file accompanying this file. This file is distributed
11-
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
* express or implied. See the License for the specific language governing
13-
* permissions and limitations under the License.
14-
*/
15-
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
163
package com.amazon.ion.impl;
174

185
import static com.amazon.ion.SystemSymbols.ION_1_0;
@@ -267,6 +254,7 @@ private static final class IonReaderTextSpan
267254
implements Span, TextSpan, OffsetSpan
268255
{
269256
private final UnifiedDataPageX _data_page;
257+
private final SymbolTable _symbols;
270258
private final IonType _container_type;
271259

272260
private final long _start_offset;
@@ -284,6 +272,7 @@ private static final class IonReaderTextSpan
284272
// page of buffered input Which is the case for the time
285273
// being. Later, when this is stream aware, this needs to change.
286274
_data_page = current_stream._buffer.getCurrentPage();
275+
_symbols = reader.getSymbolTable();
287276
_container_type = reader.getContainerType();
288277

289278
_start_offset = reader._value_start_offset - reader._physical_start_offset;
@@ -391,6 +380,7 @@ private void hoistImpl(Span span)
391380
}
392381
IonType container = text_span.getContainerType();
393382
re_init(iis, container, text_span._start_line, text_span._start_column);
383+
_symbols = text_span._symbols;
394384
}
395385

396386

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
package com.amazon.ion;
4+
5+
import com.amazon.ion.facet.Facets;
6+
import com.amazon.ion.system.IonReaderBuilder;
7+
import org.junit.Test;
8+
import org.junit.jupiter.api.Assertions;
9+
10+
import java.io.IOException;
11+
12+
public class TextSpanHoistingTest
13+
{
14+
@Test
15+
public void hoistingTextSpanAlsoHoistsSymbolTable() throws IOException {
16+
String textWithSymbolTables =
17+
"$ion_1_0 $ion_symbol_table::{ symbols:[\"bar\"] } { foo1: $10 }" +
18+
"$ion_1_0 $ion_symbol_table::{ symbols:[\"baz\"] } { foo2: $10 }";
19+
20+
IonReader reader = IonReaderBuilder.standard().build(textWithSymbolTables);
21+
SeekableReader seekableReader = Facets.asFacet(SeekableReader.class, reader);
22+
23+
Assertions.assertEquals(IonType.STRUCT, reader.next());
24+
Span span = seekableReader.currentSpan();
25+
reader.stepIn();
26+
Assertions.assertEquals(IonType.SYMBOL, reader.next());
27+
Assertions.assertEquals("foo1", reader.getFieldName());
28+
Assertions.assertEquals("bar", reader.stringValue());
29+
reader.stepOut();
30+
31+
Assertions.assertEquals(IonType.STRUCT, reader.next());
32+
reader.stepIn();
33+
Assertions.assertEquals(IonType.SYMBOL, reader.next());
34+
Assertions.assertEquals("foo2", reader.getFieldName());
35+
Assertions.assertEquals("baz", reader.stringValue());
36+
reader.stepOut();
37+
38+
// now re-seek to the first value
39+
seekableReader.hoist(span);
40+
41+
Assertions.assertEquals(IonType.STRUCT, reader.next());
42+
reader.stepIn();
43+
Assertions.assertEquals(IonType.SYMBOL, reader.next());
44+
Assertions.assertEquals("foo1", reader.getFieldName());
45+
46+
// this assertion fails
47+
Assertions.assertEquals("bar", reader.stringValue());
48+
reader.stepOut();
49+
}
50+
}

0 commit comments

Comments
 (0)