Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Symbol Lookup with Hoisted Text Span #1042

Closed
rmarrowstone opened this issue Jan 28, 2025 · 0 comments · Fixed by #1043
Closed

Incorrect Symbol Lookup with Hoisted Text Span #1042

rmarrowstone opened this issue Jan 28, 2025 · 0 comments · Fixed by #1043
Labels

Comments

@rmarrowstone
Copy link
Contributor

I was playing with capturing and hoisting spans and discovered that the text capture/hoist implementation does not capture the current symbol tables. While I think the likelihood anyone encounters this in production is quite low, I wanted to report it for awareness.

The test below shows my expectation and points out which assertion currently fails:

    @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();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant