Skip to content
Snippets Groups Projects

#3182213 Add crossorigin attribute to script tags

Open #3182213 Add crossorigin attribute to script tags
3 unresolved threads
Open Daniel Kulbe requested to merge issue/cdn-3182213:3182213-crossorigin-attribute into 4.x
3 unresolved threads
  • check response for all domains configured in settings
  • update script tags in response content

Closes #3182213

Merge request reports

Members who can merge are allowed to add commits.
Approval is optional
Ready to merge by members who can write to the target branch.
  • The source branch is 12 commits behind the target branch.
  • 1 commit will be added to 4.x.
  • Source branch will be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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
  • 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) . '\/.*"/';
  • 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) {
  • Wim Leers
  • Wim Leers added 1 commit

    added 1 commit

    • d572cc4f - Apply 2 suggestion(s) to 1 file(s)

    Compare with previous version

  • Daniel Kulbe changed target branch from 8.x-3.x to 4.x

    changed target branch from 8.x-3.x to 4.x

  • Daniel Kulbe added 1 commit

    added 1 commit

    Compare with previous version

  • Daniel Kulbe added 13 commits

    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...

    Compare with previous version

  • Daniel Kulbe added 1 commit

    added 1 commit

    Compare with previous version

  • Please register or sign in to reply
    Loading