Unverified Commit 3235c6f8 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] Fix a buggy serializer (#79520)

Because regexes aren't naively serializable, we use a simple alternate representation and then just re-parse them when deserializing.  A trivial bug was introduced in #78251  that has broken deserialization.  Fix that and add a unit test.

My only defense for such a silly mistake is that this was my first PR 🤦‍♂️
parent ed2db11e
...@@ -9508,6 +9508,7 @@ dependencies = [ ...@@ -9508,6 +9508,7 @@ dependencies = [
"regex", "regex",
"regress", "regress",
"serde", "serde",
"serde_json",
"turbo-tasks", "turbo-tasks",
"turbo-tasks-build", "turbo-tasks-build",
] ]
......
...@@ -9,6 +9,7 @@ anyhow = { workspace = true } ...@@ -9,6 +9,7 @@ anyhow = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
regress = { workspace = true } regress = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
[build-dependencies] [build-dependencies]
......
...@@ -43,7 +43,7 @@ impl TryFrom<RegexForm> for EsRegex { ...@@ -43,7 +43,7 @@ impl TryFrom<RegexForm> for EsRegex {
type Error = anyhow::Error; type Error = anyhow::Error;
fn try_from(value: RegexForm) -> std::result::Result<Self, Self::Error> { fn try_from(value: RegexForm) -> std::result::Result<Self, Self::Error> {
EsRegex::new(&value.pattern, &value.pattern) EsRegex::new(&value.pattern, &value.flags)
} }
} }
...@@ -87,7 +87,7 @@ impl EsRegex { ...@@ -87,7 +87,7 @@ impl EsRegex {
'u' => applied_flags.push('u'), 'u' => applied_flags.push('u'),
// sticky search: not relevant for the regex itself // sticky search: not relevant for the regex itself
'y' => {} 'y' => {}
_ => bail!("unsupported flag `{}` in regex", flag), _ => bail!("unsupported flag `{flag}` in regex: `{pattern}` with flags: `{flags}`"),
} }
} }
...@@ -129,6 +129,14 @@ impl EsRegex { ...@@ -129,6 +129,14 @@ impl EsRegex {
mod tests { mod tests {
use super::{EsRegex, EsRegexImpl}; use super::{EsRegex, EsRegexImpl};
#[test]
fn round_trip_serialize() {
let regex = EsRegex::new("[a-z]", "i").unwrap();
let serialized = serde_json::to_string(&regex).unwrap();
let parsed = serde_json::from_str::<EsRegex>(&serialized).unwrap();
assert_eq!(regex, parsed);
}
#[test] #[test]
fn es_regex_matches_simple() { fn es_regex_matches_simple() {
let regex = EsRegex::new("a", "").unwrap(); let regex = EsRegex::new("a", "").unwrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment