From 2d2c5bb1014efeeee47f59ce99cb0f1fece90fae Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Tue, 4 Oct 2022 17:09:50 -0400 Subject: [PATCH] Make JSONObject name regex pcre2-compatible (#89) --- src/JSONPath/JSONObject.hack | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/JSONPath/JSONObject.hack b/src/JSONPath/JSONObject.hack index fdfcf72..436b5ff 100755 --- a/src/JSONPath/JSONObject.hack +++ b/src/JSONPath/JSONObject.hack @@ -323,14 +323,16 @@ class JSONObject { return null; } - $child_name_regex = re"/^\.(?(?\"?)[[:alpha:]_$][\w-$]*(?\\2)|\*)(?.*)$/"; + $child_name_regex = re"/^\.(?(?\"?)[[:alpha:]_$][a-zA-Z0-9_\-\$]*(?\\2)|\*)(?.*)$/"; $matched = Regex\first_match($jsonPath, $child_name_regex); if ($matched) { // Remove double quotedness if matched - $child = ($matched['quote0'] === '"' && $matched['quote1'] === '"') - ? Str\strip_prefix($matched['child'], '"') |> Str\strip_suffix($$, '"') - : $matched['child']; + if ($matched['quote0'] === '"' && $matched['quote1'] === '"') { + $child = Str\strip_prefix($matched['child'], '"') |> Str\strip_suffix($$, '"'); + } else { + $child = $matched['child']; + } return shape( 'child' => $child,