Diff
checker
Texto
Texto
Imágenes
Documentos
Excel
Carpetas
Legal
Enterprise
Aplicación de escritorio
Precios
Iniciar sesión
Descargar Diffchecker Desktop
Comparar texto
Encuentra la diferencia entre dos archivos de texto
Herramientas
Historial
Editor live
Ocultar sin cambios
Sin ajuste de línea
Vista
Dividido
Unificado
Nivel de detalle
Inteligente
Palabra
Letra
Resaltado de sintaxis
Elegir sintaxis
Ignorar
Transformar texto
Ir al primer cambio
Editar entrada
Diffchecker Desktop
La forma más segura de usar Diffchecker. ¡Obtén la app de Diffchecker Desktop: tus diffs nunca salen de tu computadora!
Obtener Desktop
interdiff_3360661_3382821
Creado
hace 3 años
El diff nunca expira
Borrar
Exportar
Compartir
Explicar
4 eliminaciones
Líneas
Total
Eliminado
Caracteres
Total
Eliminado
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
118 líneas
Copiar todo
20 adiciones
Líneas
Total
Añadido
Caracteres
Total
Añadido
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
129 líneas
Copiar todo
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
Copiar
Copiado
Copiar
Copiado
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
Copiar
Copiado
Copiar
Copiado
@@ -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) {
Copiar
Copiado
Copiar
Copiado
- 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) {
Copiar
Copiado
Copiar
Copiado
+
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);
Diferencias guardadas
Texto original
Abrir archivo
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);
Texto modificado
Abrir archivo
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);
Encontrar la diferencia