diff --git a/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java b/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java index edd1a1faf..166455d0d 100644 --- a/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java +++ b/pkl-core/src/main/java/org/pkl/core/util/pklbinary/AbstractPklBinaryDecoder.java @@ -31,6 +31,7 @@ import org.msgpack.core.MessageUnpacker; import org.pkl.core.DataSizeUnit; import org.pkl.core.DurationUnit; import org.pkl.core.Pair; +import org.pkl.core.runtime.VmUtils; import org.pkl.core.util.LateInit; /** @@ -317,10 +318,11 @@ public abstract class AbstractPklBinaryDecoder { return result; } + @SuppressWarnings("MagicConstant") private Object decodeRegex(int len) throws IOException { assertLength(PklBinaryCode.REGEX, len, 1); currPath.push("'regex"); - var result = doDecodeRegex(Pattern.compile(unpacker.unpackString())); + var result = doDecodeRegex(Pattern.compile(unpacker.unpackString(), VmUtils.REGEX_FLAGS)); unpacker.skipValue(len - 2); currPath.pop(); return result; diff --git a/pkl-core/src/test/kotlin/org/pkl/core/PklBinaryDecoderTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/PklBinaryDecoderTest.kt index 664f58395..f4a82ef08 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/PklBinaryDecoderTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/PklBinaryDecoderTest.kt @@ -20,6 +20,7 @@ import java.util.regex.Pattern import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import org.msgpack.core.MessagePack import org.pkl.core.util.pklbinary.PklBinaryCode class PklBinaryDecoderTest { @@ -261,4 +262,14 @@ class PklBinaryDecoderTest { "Unable to decode set of length 65536, exceeded maximum collection size", ) } + + @Test + fun `decode regex preserves Pkl's implicit flags`() { + val packer = MessagePack.newDefaultBufferPacker() + packer.packArrayHeader(2) + packer.packByte(0x0B) + packer.packString("(?i)é") + val decoded = PklBinaryDecoder.decode(packer.toByteArray()) as Pattern + assertThat(decoded.matcher("É")).matches() + } }