Skip to content

Commit

Permalink
Make JSONObject name regex pcre2-compatible (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug authored Oct 4, 2022
1 parent 236abf8 commit 2d2c5bb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/JSONPath/JSONObject.hack
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,16 @@ class JSONObject {
return null;
}

$child_name_regex = re"/^\.(?<child>(?<quote0>\"?)[[:alpha:]_$][\w-$]*(?<quote1>\\2)|\*)(?<rest>.*)$/";
$child_name_regex = re"/^\.(?<child>(?<quote0>\"?)[[:alpha:]_$][a-zA-Z0-9_\-\$]*(?<quote1>\\2)|\*)(?<rest>.*)$/";
$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,
Expand Down

0 comments on commit 2d2c5bb

Please sign in to comment.