Skip to content

Commit ad1db11

Browse files
committed
HTML API: Add sentinels for unreachable code.
There are places in the HTML API code where some tools get confused and flag invalid types for the return of a function because they are unable to detect that the end of the function is unreachable. Since PHP doesn't provide a way to encode total matching in the source code, this patch adds a few extra lines in those unreachable locations to satisfy any tooling which isn't able to fully analyze the code. Additionally this serves as extra guarding in case someone changes these functions in a way which would break them and the existing test suite doesn't catch those breakages. Developed in #7315 Discussed in https://core.trac.wordpress.org/ticket/62018 Props dlh, dmsnell. Fixes #62018. git-svn-id: https://develop.svn.wordpress.org/trunk@59001 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 13e0e50 commit ad1db11

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,10 @@ private function step_in_body(): bool {
27702770
}
27712771
}
27722772
}
2773+
2774+
$this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
2775+
// This unnecessary return prevents tools from inaccurately reporting type errors.
2776+
return false;
27732777
}
27742778

27752779
/**
@@ -4645,6 +4649,10 @@ private function step_in_foreign_content(): bool {
46454649
$this->bail( "Unaware of the requested parsing mode: '{$this->state->insertion_mode}'." );
46464650
}
46474651
}
4652+
4653+
$this->bail( 'Should not have been able to reach end of IN FOREIGN CONTENT processing. Check HTML API code.' );
4654+
// This unnecessary return prevents tools from inaccurately reporting type errors.
4655+
return false;
46484656
}
46494657

46504658
/*
@@ -5878,6 +5886,10 @@ private function is_html_integration_point(): bool {
58785886
)
58795887
);
58805888
}
5889+
5890+
$this->bail( 'Should not have reached end of HTML Integration Point detection: check HTML API code.' );
5891+
// This unnecessary return prevents tools from inaccurately reporting type errors.
5892+
return false;
58815893
}
58825894

58835895
/**

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,9 @@ public function get_qualified_tag_name(): ?string {
29652965
return $lower_tag_name;
29662966
}
29672967
}
2968+
2969+
// This unnecessary return prevents tools from inaccurately reporting type errors.
2970+
return $tag_name;
29682971
}
29692972

29702973
/**

0 commit comments

Comments
 (0)