Skip to content

Commit

Permalink
Merge pull request #2245 from WordPress/feature/enqueuedresources-bri…
Browse files Browse the repository at this point in the history
…ng-back-try-catch
  • Loading branch information
GaryJones committed May 28, 2023
2 parents 6efe2f6 + 1dc9d7f commit a328aff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions WordPress/Sniffs/WP/EnqueuedResourcesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace WordPressCS\WordPress\Sniffs\WP;

use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Util\Tokens;
use PHPCSUtils\Tokens\Collections;
use PHPCSUtils\Utils\TextStrings;
Expand Down Expand Up @@ -53,8 +54,13 @@ public function process_token( $stackPtr ) {
$end_ptr = $stackPtr;
$content = $this->tokens[ $stackPtr ]['content'];
if ( \T_INLINE_HTML !== $this->tokens[ $stackPtr ]['code'] ) {
$end_ptr = TextStrings::getEndOfCompleteTextString( $this->phpcsFile, $stackPtr );
$content = TextStrings::getCompleteTextString( $this->phpcsFile, $stackPtr );
try {
$end_ptr = TextStrings::getEndOfCompleteTextString( $this->phpcsFile, $stackPtr );
$content = TextStrings::getCompleteTextString( $this->phpcsFile, $stackPtr );
} catch ( RuntimeException $e ) {
// Parse error/live coding.
return;
}
}

if ( preg_match_all( '# rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $content, $matches, \PREG_OFFSET_CAPTURE ) > 0 ) {
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Tests/WP/EnqueuedResourcesUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ echo '<script type="text/javascript"
// Test multi-line text string with multiple issues.
echo '<link rel="stylesheet" href="https://someurl/somefile1.css"/>
<link rel="stylesheet" href="https://someurl/somefile2.css"/>';

// Safeguard the handling of a particular type of parse error (forgotten concat operator).
echo 'not a text we need to worry' 'about anyway, but we shouldn\'t see an uncaught runtime exception because of it';

0 comments on commit a328aff

Please sign in to comment.