Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
interdiff_3360661_3382821
创建于
3年前
差异永不过期
清除
导出
分享
解释
4 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
118 行
全部复制
20 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
129 行
全部复制
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);
已保存差异
原始文本
打开文件
diff --git a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php index d164700..267e636 100644 --- a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php +++ b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php @@ -116,69 +116,65 @@ class ConvertUrlToEmbedFilter extends FilterBase { // markup, especially a '>'. Therefore, remove all comment contents and add // them back later. _filter_url_escape_comments('', TRUE); - $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. - $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE); - // PHP ensures that the array consists of alternating delimiters and - // literals, and begins and ends with a literal (inserting NULL as - // required). Therefore, the first chunk is always text: - $chunk_type = 'text'; - // 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, - // no replacements are made. - $open_tag = ''; - - for ($i = 0; $i < count($chunks); $i++) { - if ($chunk_type == 'text') { - // Only process this text if there are no unclosed $ignore_tags. - if ($open_tag == '') { - // If there is a match, inject a link into this chunk via the callback - // function contained in $task. - $chunks[$i] = preg_replace_callback( - $pattern, - function ($match) { - try { - $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1])); - if ($info) { + $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. + if ($chunks !== FALSE) { + // PHP ensures that the array consists of alternating delimiters and + // literals, and begins and ends with a literal (inserting NULL as + // required). Therefore, the first chunk is always text: + $chunk_type = 'text'; + // 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, + // no replacements are made. + $open_tag = ''; + for ($i = 0; $i < count($chunks); $i++) { + if ($chunk_type == 'text') { + // Only process this text if there are no unclosed $ignore_tags. + if ($open_tag == '') { + // If there is a match, inject a link into this chunk via the callback + // function contained in $task. + $chunks[$i] = preg_replace_callback( + $pattern, + function ($match) { + if (\Drupal::service('url_embed')->getEmbed(Html::decodeEntities($match[1]))) { 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]; - } - }, - $chunks[$i] - ); - } - // Text chunk is done, so next chunk must be a tag. - $chunk_type = 'tag'; - } - else { - // Only process this tag if there are no unclosed $ignore_tags. - if ($open_tag == '') { - // Check whether this tag is contained in $ignore_tags. - if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) { - $open_tag = $matches[1]; + }, + $chunks[$i] + ); } + // Text chunk is done, so next chunk must be a tag. + $chunk_type = 'tag'; } - // Otherwise, check whether this is the closing tag for $open_tag. else { - if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) { - $open_tag = ''; + // Only process this tag if there are no unclosed $ignore_tags. + if ($open_tag == '') { + // Check whether this tag is contained in $ignore_tags. + if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) { + $open_tag = $matches[1]; + } } + // Otherwise, check whether this is the closing tag for $open_tag. + else { + if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) { + $open_tag = ''; + } + } + // Tag chunk is done, so next chunk must be text. + $chunk_type = 'text'; } - // Tag chunk is done, so next chunk must be text. - $chunk_type = 'text'; } + + $text = implode($chunks); } - $text = implode($chunks); // Revert to the original comment contents _filter_url_escape_comments('', FALSE); return preg_replace_callback('`<!--(.*?)-->`', '_filter_url_escape_comments', $text);
更改后文本
打开文件
diff --git a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php index d164700..a77c573 100644 --- a/src/Plugin/Filter/ConvertUrlToEmbedFilter.php +++ b/src/Plugin/Filter/ConvertUrlToEmbedFilter.php @@ -116,69 +116,73 @@ class ConvertUrlToEmbedFilter extends FilterBase { // markup, especially a '>'. Therefore, remove all comment contents and add // them back later. _filter_url_escape_comments('', TRUE); - $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. - $chunks = preg_split('/(<.+?>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE); - // PHP ensures that the array consists of alternating delimiters and - // literals, and begins and ends with a literal (inserting NULL as - // required). Therefore, the first chunk is always text: - $chunk_type = 'text'; - // 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, - // no replacements are made. - $open_tag = ''; - - for ($i = 0; $i < count($chunks); $i++) { - if ($chunk_type == 'text') { - // Only process this text if there are no unclosed $ignore_tags. - if ($open_tag == '') { - // If there is a match, inject a link into this chunk via the callback - // function contained in $task. - $chunks[$i] = preg_replace_callback( - $pattern, - function ($match) { - try { - $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1])); - 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); + + // Do not attempt to convert links into URLs if preg_split() fails. + if ($chunks !== FALSE) { + // PHP ensures that the array consists of alternating delimiters and + // literals, and begins and ends with a literal (inserting NULL as + // required). Therefore, the first chunk is always text: + $chunk_type = 'text'; + // 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, + // no replacements are made. + $open_tag = ''; + for ($i = 0; $i < count($chunks); $i++) { + if ($chunk_type == 'text') { + // Only process this text if there are no unclosed $ignore_tags. + if ($open_tag == '') { + // If there is a match, inject a link into this chunk via the callback + // function contained in $task. + $chunks[$i] = preg_replace_callback( + $pattern, + function ($match) { + try { + $info = \Drupal::service('url_embed')->getUrlInfo(Html::decodeEntities($match[1])); + if ($info) { + 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]; } - } 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]; - } - }, - $chunks[$i] - ); - } - // Text chunk is done, so next chunk must be a tag. - $chunk_type = 'tag'; - } - else { - // Only process this tag if there are no unclosed $ignore_tags. - if ($open_tag == '') { - // Check whether this tag is contained in $ignore_tags. - if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) { - $open_tag = $matches[1]; + }, + $chunks[$i] + ); } + // Text chunk is done, so next chunk must be a tag. + $chunk_type = 'tag'; } - // Otherwise, check whether this is the closing tag for $open_tag. else { - if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) { - $open_tag = ''; + // Only process this tag if there are no unclosed $ignore_tags. + if ($open_tag == '') { + // Check whether this tag is contained in $ignore_tags. + if (preg_match("`<($ignore_tags)(?:\s|>)`i", $chunks[$i], $matches)) { + $open_tag = $matches[1]; + } } + // Otherwise, check whether this is the closing tag for $open_tag. + else { + if (preg_match("`<\/$open_tag>`i", $chunks[$i], $matches)) { + $open_tag = ''; + } + } + // Tag chunk is done, so next chunk must be text. + $chunk_type = 'text'; } - // Tag chunk is done, so next chunk must be text. - $chunk_type = 'text'; } + + $text = implode($chunks); } - $text = implode($chunks); // Revert to the original comment contents _filter_url_escape_comments('', FALSE); return preg_replace_callback('`<!--(.*?)-->`', '_filter_url_escape_comments', $text);
查找差异