#3182213 Add crossorigin attribute to script tags
3 unresolved threads
3 unresolved threads
- check response for all domains configured in settings
- update script tags in response content
Closes #3182213
Merge request reports
Activity
- Resolved by Wim Leers
78 80 } 79 81 } 80 82 83 /** 84 * Adds crossorigin attribute to script tags. 85 * 86 * @param \Drupal\Core\Render\HtmlResponse $response 87 * The HTML response to update. 88 * 89 * @see https://www.w3.org/TR/2014/REC-html5-20141028/scripting-1.html#attr-script-crossorigin 90 */ 91 protected function addScriptCrossOrigin(HtmlResponse $response) { 92 $content = $response->getContent(); 93 foreach ($this->settings->getDomains() as $domain) { 94 $pattern = '/<script src="(?:https?:)?\/\/' . quotemeta($domain) . '\/.*"/'; TIL https://www.php.net/manual/en/function.quotemeta.php — never heard of this before!
Shouldn't this use
preg_quote()
though?
94 $pattern = '/<script src="(?:https?:)?\/\/' . quotemeta($domain) . '\/.*"/'; 95 $content = preg_replace_callback($pattern, [$this, 'updateScriptTag'], $content); 96 } 97 $response->setContent($content); 98 } 99 100 /** 101 * Callback to replace individual script links. 102 * 103 * @param array $matches 104 * Array from matches from preg_replace_callback. 105 * 106 * @return string 107 * Updated html string. 108 */ 109 protected function updateScriptTag(array $matches) { changed this line in version 5 of the diff
- Resolved by Wim Leers
added 13 commits
-
6b69bbdd...9f2e5a00 - 9 commits from branch
project:4.x
- 2f988b08 - * check response for all domains configured in settings
- 1d65c3ea - Apply 2 suggestion(s) to 1 file(s)
- 80646f8c - Update for 4.x
- ff90c4dd - Merge branch '3182213-crossorigin-attribute' of...
Toggle commit list-
6b69bbdd...9f2e5a00 - 9 commits from branch
Please register or sign in to reply