Skip to content

Commit

Permalink
Fix Hoisted Text Span Symbol Table Bug
Browse files Browse the repository at this point in the history
Fixes #1042
  • Loading branch information
rmarrowstone committed Jan 28, 2025
1 parent 7a89a85 commit 01dbdbc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/main/java/com/amazon/ion/impl/IonReaderTextUserX.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 Down Expand Up @@ -267,6 +254,7 @@ private static final class IonReaderTextSpan
implements Span, TextSpan, OffsetSpan
{
private final UnifiedDataPageX _data_page;
private final SymbolTable _symbols;
private final IonType _container_type;

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

_start_offset = reader._value_start_offset - reader._physical_start_offset;
Expand Down Expand Up @@ -391,6 +380,7 @@ private void hoistImpl(Span span)
}
IonType container = text_span.getContainerType();
re_init(iis, container, text_span._start_line, text_span._start_column);
_symbols = text_span._symbols;
}


Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/amazon/ion/TextSpanHoistingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package com.amazon.ion;

import com.amazon.ion.facet.Facets;
import com.amazon.ion.system.IonReaderBuilder;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import java.io.IOException;

public class TextSpanHoistingTest
{
@Test
public void hoistingTextSpanAlsoHoistsSymbolTable() throws IOException {
String textWithSymbolTables =
"$ion_1_0 $ion_symbol_table::{ symbols:[\"bar\"] } { foo1: $10 }" +
"$ion_1_0 $ion_symbol_table::{ symbols:[\"baz\"] } { foo2: $10 }";

IonReader reader = IonReaderBuilder.standard().build(textWithSymbolTables);
SeekableReader seekableReader = Facets.asFacet(SeekableReader.class, reader);

Assertions.assertEquals(IonType.STRUCT, reader.next());
Span span = seekableReader.currentSpan();
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo1", reader.getFieldName());
Assertions.assertEquals("bar", reader.stringValue());
reader.stepOut();

Assertions.assertEquals(IonType.STRUCT, reader.next());
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo2", reader.getFieldName());
Assertions.assertEquals("baz", reader.stringValue());
reader.stepOut();

// now re-seek to the first value
seekableReader.hoist(span);

Assertions.assertEquals(IonType.STRUCT, reader.next());
reader.stepIn();
Assertions.assertEquals(IonType.SYMBOL, reader.next());
Assertions.assertEquals("foo1", reader.getFieldName());

// this assertion fails
Assertions.assertEquals("bar", reader.stringValue());
reader.stepOut();
}
}

0 comments on commit 01dbdbc

Please sign in to comment.