Comparing sensitive data, confidential files or internal emails?

Most legal and privacy policies prohibit uploading sensitive data online. Diffchecker Desktop ensures your confidential information never leaves your computer. Work offline and compare documents securely.

interdiff_3360661_3382821

Created Diff never expires
3 removals
118 lines
20 additions
129 lines
diff --git a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
diff --git a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
index d164700..267e636 100644
index d164700..a77c573 100644
--- a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
--- a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
+++ b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
+++ b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php
@@ -116,69 +116,65 @@ class ConvertUrlToEmbedFilter extends FilterBase {
@@ -116,69 +116,73 @@ class ConvertUrlToEmbedFilter extends FilterBase {
// markup, especially a '>'. Therefore, remove all comment contents and add
// markup, especially a '>'. Therefore, remove all comment contents and add
// them back later.
// them back later.
_filter_url_escape_comments('', TRUE);
_filter_url_escape_comments('', TRUE);
- $text = preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
- $text = preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
+ $text = is_null($text) ? '' : preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
+ $text = is_null($text) ? '' : preg_replace_callback('`<!--(.*?)-->`s', '_filter_url_escape_comments', $text);
// Split at all tags; ensures that no tags or attributes are processed.
// Split at all tags; ensures that no tags or attributes are processed.
- $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
- $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
- // PHP ensures that the array consists of alternating delimiters and
- // PHP ensures that the array consists of alternating delimiters and
- // literals, and begins and ends with a literal (inserting NULL as
- // literals, and begins and ends with a literal (inserting NULL as
- // required). Therefore, the first chunk is always text:
- // required). Therefore, the first chunk is always text:
- $chunk_type = 'text';
- $chunk_type = 'text';
- // If a tag of $ignore_tags is found, it is stored in $open_tag and only
- // If a tag of $ignore_tags is found, it is stored in $open_tag and only
- // removed when the closing tag is found. Until the closing tag is found,
- // removed when the closing tag is found. Until the closing tag is found,
- // no replacements are made.
- // no replacements are made.
- $open_tag = '';
- $open_tag = '';
-
-
- for ($i = 0; $i < count($chunks); $i++) {
- for ($i = 0; $i < count($chunks); $i++) {
- if ($chunk_type == 'text') {
- if ($chunk_type == 'text') {
- // Only process this text if there are no unclosed $ignore_tags.
- // Only process this text if there are no unclosed $ignore_tags.
- if ($open_tag == '') {
- if ($open_tag == '') {
- // If there is a match, inject a link into this chunk via the callback
- // If there is a match, inject a link into this chunk via the callback
- // function contained in $task.
- // function contained in $task.
- $chunks[$i] = preg_replace_callback(
- $chunks[$i] = preg_replace_callback(
- $pattern,
- $pattern,
- function ($match) {
- function ($match) {
- try {
- try {
- $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1]));
- $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1]));
- if ($info) {
- if ($info) {
- return '<drupal-url data-embed-url="' . $match[1] . '"></drupal-url>';
- }
- else {
+ $chunks = is_null($text) ? [''] : preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $chunks = is_null($text) ? [''] : preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+
+
+ // Do not attempt to convert links into URLs if preg_split() fails.
+ // Do not attempt to convert links into URLs if preg_split() fails.
+ if ($chunks !== FALSE) {
+ if ($chunks !== FALSE) {
+ // PHP ensures that the array consists of alternating delimiters and
+ // PHP ensures that the array consists of alternating delimiters and
+ // literals, and begins and ends with a literal (inserting NULL as
+ // literals, and begins and ends with a literal (inserting NULL as
+ // required). Therefore, the first chunk is always text:
+ // required). Therefore, the first chunk is always text:
+ $chunk_type = 'text';
+ $chunk_type = 'text';
+ // If a tag of $ignore_tags is found, it is stored in $open_tag and only
+ // If a tag of $ignore_tags is found, it is stored in $open_tag and only
+ // removed when the closing tag is found. Until the closing tag is found,
+ // removed when the closing tag is found. Until the closing tag is found,
+ // no replacements are made.
+ // no replacements are made.
+ $open_tag = '';
+ $open_tag = '';
+ for ($i = 0; $i < count($chunks); $i++) {
+ for ($i = 0; $i < count($chunks); $i++) {
+ if ($chunk_type == 'text') {
+ if ($chunk_type == 'text') {
+ // Only process this text if there are no unclosed $ignore_tags.
+ // Only process this text if there are no unclosed $ignore_tags.
+ if ($open_tag == '') {
+ if ($open_tag == '') {
+ // If there is a match, inject a link into this chunk via the callback
+ // If there is a match, inject a link into this chunk via the callback
+ // function contained in $task.
+ // function contained in $task.
+ $chunks[$i] = preg_replace_callback(
+ $chunks[$i] = preg_replace_callback(
+ $pattern,
+ $pattern,
+ function ($match) {
+ function ($match) {
+ if (\Drupal::service('url_embed')->getEmbed(Html::decodeEntities($match[1]))) {
+ try {
return '<drupal-url data-embed-url="' . $match[1] . '"></drupal-url>';
+ $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1]));
}
+ if ($info) {
else {
+ return '<drupal-url data-embed-url="' . $match[1] . '"></drupal-url>';
+ }
+ else {
+ return $match[1];
+ }
+ } catch (\Exception $e) {
+ // If anything goes wrong while retrieving remote data, catch
+ // the exception to avoid a WSOD and leave the URL as is.
+ watchdog_exception('url_embed', $e);
return $match[1];
return $match[1];
}
}
- } catch (\Exception $e) {
- } catch (\Exception $e) {
- // If anything goes wrong while retrieving remote data, catch
- // If anything goes wrong while retrieving remote data, catch
- // the exception to avoid a WSOD and leave the URL as is.
- // the exception to avoid a WSOD and leave the URL as is.
- watchdog_exception('url_embed', $e);
- watchdog_exception('url_embed', $e);
- return $match[1];
- return $match[1];
- }
- }
- },
- },
- $chunks[$i]
- $chunks[$i]
- );
- );
- }
- }
- // Text chunk is done, so next chunk must be a tag.
- // Text chunk is done, so next chunk must be a tag.
- $chunk_type = 'tag';
- $chunk_type = 'tag';
- }
- }
- else {
- else {
- // Only process this tag if there are no unclosed $ignore_tags.
- // Only process this tag if there are no unclosed $ignore_tags.
- if ($open_tag == '') {
- if ($open_tag == '') {
- // Check whether this tag is contained in $ignore_tags.
- // Check whether this tag is contained in $ignore_tags.
- if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) {
- if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) {
- $open_tag = $matches[1];
- $open_tag = $matches[1];
+ },
+ },
+ $chunks[$i]
+ $chunks[$i]
+ );
+ );
}
}
+ // Text chunk is done, so next chunk must be a tag.
+ // Text chunk is done, so next chunk must be a tag.
+ $chunk_type = 'tag';
+ $chunk_type = 'tag';
}
}
- // Otherwise, check whether this is the closing tag for $open_tag.
- // Otherwise, check whether this is the closing tag for $open_tag.
else {
else {
- if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) {
- if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) {
- $open_tag = '';
- $open_tag = '';
+ // Only process this tag if there are no unclosed $ignore_tags.
+ // Only process this tag if there are no unclosed $ignore_tags.
+ if ($open_tag == '') {
+ if ($open_tag == '') {
+ // Check whether this tag is contained in $ignore_tags.
+ // Check whether this tag is contained in $ignore_tags.
+ if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) {
+ if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) {
+ $open_tag = $matches[1];
+ $open_tag = $matches[1];
+ }
+ }
}
}
+ // Otherwise, check whether this is the closing tag for $open_tag.
+ // Otherwise, check whether this is the closing tag for $open_tag.
+ else {
+ else {
+ if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) {
+ if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) {
+ $open_tag = '';
+ $open_tag = '';
+ }
+ }
+ }
+ }
+ // Tag chunk is done, so next chunk must be text.
+ // Tag chunk is done, so next chunk must be text.
+ $chunk_type = 'text';
+ $chunk_type = 'text';
}
}
- // Tag chunk is done, so next chunk must be text.
- // Tag chunk is done, so next chunk must be text.
- $chunk_type = 'text';
- $chunk_type = 'text';
}
}
+
+
+ $text = implode($chunks);
+ $text = implode($chunks);
}
}
- $text = implode($chunks);
- $text = implode($chunks);
// Revert to the original comment contents
// Revert to the original comment contents
_filter_url_escape_comments('', FALSE);
_filter_url_escape_comments('', FALSE);
return preg_replace_callback('`<!--(.*?)-->`', '_filter_url_escape_comments', $text);
return preg_replace_callback('`<!--(.*?)-->`', '_filter_url_escape_comments', $text);