Explorar el Código

Log failed CSS content retrievals (#9077)

* Log failed CSS content retrievals

## Summary

- Log a warning when a CSS content selector matches no elements.
- Log a distinct warning when matched content becomes empty after sanitization.
- Avoid duplicate warnings for the no-match case.

## Why

CSS-based content retrieval otherwise fails silently when a publisher changes its markup.

Fixes #8875.

* Avoid duplicate CSS retrieval warnings

* Typographic quotes

---------

Co-authored-by: Gerard Alvear <gerard.alvear@logiqd.me>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Gerard Alvear Porras hace 5 días
padre
commit
5b988957a2
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      app/Models/Entry.php

+ 6 - 1
app/Models/Entry.php

@@ -985,7 +985,9 @@ class FreshRSS_Entry extends Minz_Model {
 			$cssSelector = trim($cssSelector, ', ');
 			$path_entries_filter = trim($feed->attributeString('path_entries_filter') ?? '', ', ');
 			$nodes = $xpath->query((new Gt\CssXPath\Translator($cssSelector, '//'))->asXPath());
-			if ($nodes != false) {
+			if ($nodes === false || $nodes->length === 0) {
+				Minz_Log::warning('CSS content retrieval matched no elements for feed “' . $feed->name() . '” and article URL ' . $url . ': ' . $cssSelector);
+			} else {
 				$filter_xpath = $path_entries_filter === '' ? '' : (new Gt\CssXPath\Translator($path_entries_filter, 'descendant-or-self::'))->asXPath();
 				foreach ($nodes as $node) {
 					try {
@@ -1024,6 +1026,9 @@ class FreshRSS_Entry extends Minz_Model {
 
 			unset($xpath, $doc);
 			$html = FreshRSS_SimplePieCustom::sanitizeHTML($html, $base);
+			if ($nodes !== false && $nodes->length > 0 && trim($html) === '') {
+				Minz_Log::warning('CSS content retrieval returned no content for feed “' . $feed->name() . '” and article URL ' . $url . ': ' . $cssSelector);
+			}
 
 			if ($path_entries_filter !== '') {
 				// Remove unwanted elements again after sanitizing, for CSS selectors to also match sanitized content