From eeada1a4a279cb1e8bb4db397f7ee29ff7c75593 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 18 Jun 2024 09:30:50 +0200 Subject: [PATCH 1/4] Fix a bug in the default case of escaping characters When a '\' was encountered followed by a character that has no special meaning, the character was added as an integer. For instance: '\$' was turned into the string '36' instead of the string '$'. --- .../java/io/usethesource/vallang/io/StandardTextReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/usethesource/vallang/io/StandardTextReader.java b/src/main/java/io/usethesource/vallang/io/StandardTextReader.java index 2b0e8cc5..a8e1d83f 100644 --- a/src/main/java/io/usethesource/vallang/io/StandardTextReader.java +++ b/src/main/java/io/usethesource/vallang/io/StandardTextReader.java @@ -742,7 +742,7 @@ private IValue readString(Type expected) throws IOException { if (current == -1) { throw new FactParseError("End of input before finding end of String", stream.offset); } - builder.append(current); + builder.append((char)current); } current = stream.read(); } From 09723355db0c846c87dd96f662aa09e47464ac59 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 18 Jun 2024 10:05:27 +0200 Subject: [PATCH 2/4] Added unit test to catch test fix and catch regressions --- .../vallang/io/StandardTextReaderTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java diff --git a/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java b/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java new file mode 100644 index 00000000..90752bf6 --- /dev/null +++ b/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java @@ -0,0 +1,28 @@ +package io.usethesource.vallang.io; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; +import io.usethesource.vallang.IString; +import io.usethesource.vallang.IValueFactory; +import io.usethesource.vallang.ValueProvider; +import io.usethesource.vallang.type.TypeFactory; +import io.usethesource.vallang.type.TypeStore; + +class StandardTextReaderTest { + private IString readString(IValueFactory valueFactory, TypeStore typeStore, String s) throws IOException { + Reader reader = new StringReader(s); + StandardTextReader textReader = new StandardTextReader(); + return (IString) textReader.read(valueFactory, typeStore, TypeFactory.getInstance().stringType(), reader); + + } + + @ParameterizedTest @ArgumentsSource(ValueProvider.class) + void escapeNormalCharacters(IValueFactory valueFactory, TypeStore typeStore) throws IOException { + IString s = readString(valueFactory, typeStore, "\"\\$\""); + assertEquals("$", s.getValue()); + } +} From 478d5f7e30d9944c8cabe454d6468f152facd0c9 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 18 Jun 2024 14:51:25 +0200 Subject: [PATCH 3/4] Moved test to RegressionTests --- .../vallang/io/StandardTextReaderTest.java | 28 ------------------- .../vallang/issues/RegressionTests.java | 19 ++++++++++++- 2 files changed, 18 insertions(+), 29 deletions(-) delete mode 100644 src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java diff --git a/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java b/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java deleted file mode 100644 index 90752bf6..00000000 --- a/src/test/java/io/usethesource/vallang/io/StandardTextReaderTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.usethesource.vallang.io; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ArgumentsSource; -import io.usethesource.vallang.IString; -import io.usethesource.vallang.IValueFactory; -import io.usethesource.vallang.ValueProvider; -import io.usethesource.vallang.type.TypeFactory; -import io.usethesource.vallang.type.TypeStore; - -class StandardTextReaderTest { - private IString readString(IValueFactory valueFactory, TypeStore typeStore, String s) throws IOException { - Reader reader = new StringReader(s); - StandardTextReader textReader = new StandardTextReader(); - return (IString) textReader.read(valueFactory, typeStore, TypeFactory.getInstance().stringType(), reader); - - } - - @ParameterizedTest @ArgumentsSource(ValueProvider.class) - void escapeNormalCharacters(IValueFactory valueFactory, TypeStore typeStore) throws IOException { - IString s = readString(valueFactory, typeStore, "\"\\$\""); - assertEquals("$", s.getValue()); - } -} diff --git a/src/test/java/io/usethesource/vallang/issues/RegressionTests.java b/src/test/java/io/usethesource/vallang/issues/RegressionTests.java index 987447d2..19ba0c6c 100644 --- a/src/test/java/io/usethesource/vallang/issues/RegressionTests.java +++ b/src/test/java/io/usethesource/vallang/issues/RegressionTests.java @@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; import java.io.StringWriter; import org.junit.jupiter.params.ParameterizedTest; @@ -14,8 +16,10 @@ import io.usethesource.vallang.IConstructor; import io.usethesource.vallang.ISet; import io.usethesource.vallang.ISourceLocation; +import io.usethesource.vallang.IString; import io.usethesource.vallang.IValueFactory; import io.usethesource.vallang.ValueProvider; +import io.usethesource.vallang.io.StandardTextReader; import io.usethesource.vallang.io.StandardTextWriter; import io.usethesource.vallang.type.Type; import io.usethesource.vallang.type.TypeFactory; @@ -60,5 +64,18 @@ void keywordFieldsMakeConstructorsDifferent(IValueFactory vf, TypeFactory tf, Ty assertFalse(cons1.equals(cons2)); } - + + private IString readString(IValueFactory valueFactory, TypeStore typeStore, String s) throws IOException { + Reader reader = new StringReader(s); + StandardTextReader textReader = new StandardTextReader(); + return (IString) textReader.read(valueFactory, typeStore, TypeFactory.getInstance().stringType(), reader); + + } + + @ParameterizedTest @ArgumentsSource(ValueProvider.class) + void escapeNormalCharacters(IValueFactory valueFactory, TypeStore typeStore) throws IOException { + IString s = readString(valueFactory, typeStore, "\"\\$\""); + assertEquals("$", s.getValue()); + } + } From 16ad307455db6df8de6350bfade37d650d7f1085 Mon Sep 17 00:00:00 2001 From: Pieter Olivier Date: Tue, 18 Jun 2024 15:44:56 +0200 Subject: [PATCH 4/4] Try to force StackOverflowError by increasing the depth constant The test failed to generate the expected StackOverflowError, so with this commit I try to force the error again. --- .../io/usethesource/vallang/basic/LazyStringOperationsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/usethesource/vallang/basic/LazyStringOperationsTest.java b/src/test/java/io/usethesource/vallang/basic/LazyStringOperationsTest.java index e0a85095..bc98fe5d 100644 --- a/src/test/java/io/usethesource/vallang/basic/LazyStringOperationsTest.java +++ b/src/test/java/io/usethesource/vallang/basic/LazyStringOperationsTest.java @@ -194,7 +194,7 @@ public void testStringReplace(IValueFactory vf) { @ParameterizedTest @ArgumentsSource(ValueProvider.class) public void neverRunOutOfStack(IValueFactory vf) { - int outofStack = 30000; + int outofStack = 100000; // first we have to know for sure that we would run out of stack with @see // outOfStack iterations: