Skip to content

Commit

Permalink
Fix validation of modified sparse ASTs (webonyx#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Apr 13, 2022
1 parent 81b5c6b commit 6070542
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ jobs:
- uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@2.9.0
uses: shivammathur/setup-php@2.18.1
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: json, mbstring

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

#### Unreleased

#### 14.11.6

Fixed:
- Fix validation of modified sparse ASTs

#### 14.11.5

Fixed:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true
}
},
"autoload": {
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,6 @@ parameters:
count: 1
path: src/Validator/ValidationContext.php

-
message: "#^Only booleans are allowed in an if condition, GraphQL\\\\Language\\\\AST\\\\SelectionSetNode\\|null given\\.$#"
count: 1
path: src/Validator/ValidationContext.php

-
message: "#^Only booleans are allowed in a negated boolean, array\\<GraphQL\\\\Language\\\\AST\\\\FragmentDefinitionNode\\> given\\.$#"
count: 1
Expand Down
14 changes: 7 additions & 7 deletions src/Validator/ValidationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use SplObjectStorage;
use function array_merge;
use function array_pop;
use function assert;
use function count;

/**
Expand Down Expand Up @@ -180,16 +181,15 @@ public function getFragmentSpreads(HasSelectionSet $node) : array
while (count($setsToVisit) > 0) {
$set = array_pop($setsToVisit);

for ($i = 0, $selectionCount = count($set->selections); $i < $selectionCount; $i++) {
$selection = $set->selections[$i];
foreach ($set->selections as $selection) {
if ($selection instanceof FragmentSpreadNode) {
$spreads[] = $selection;
} elseif ($selection instanceof FieldNode || $selection instanceof InlineFragmentNode) {
if ($selection->selectionSet) {
$setsToVisit[] = $selection->selectionSet;
}
} else {
throw InvariantViolation::shouldNotHappen();
assert($selection instanceof FieldNode || $selection instanceof InlineFragmentNode);
$selectionSet = $selection->selectionSet;
if ($selectionSet !== null) {
$setsToVisit[] = $selectionSet;
}
}
}
}
Expand Down

0 comments on commit 6070542

Please sign in to comment.