Просмотр исходного кода

Fix escapeToUnicodeAlternative extended mode dropping characters (#9679)

Fixes #9667

The array union operator kept the left-hand value for keys 0-2, so
', " and ^ were never replaced. Use array_merge so all extended
characters are replaced.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Aryan Pasreja 5 часов назад
Родитель
Сommit
b17f774a8d
2 измененных файлов с 8 добавлено и 2 удалено
  1. 2 2
      lib/lib_rss.php
  2. 6 0
      tests/lib/LibRssTest.php

+ 2 - 2
lib/lib_rss.php

@@ -214,8 +214,8 @@ function escapeToUnicodeAlternative(string $text, bool $extended = true): string
 
 	// https://raw.githubusercontent.com/mihaip/google-reader-api/master/wiki/StreamId.wiki
 	if ($extended) {
-		$problem += ["'", '"', '^', '?', '\\', '/', ',', ';'];
-		$replace += ["’", '"', '^', '?', '\', '/', ',', ';'];
+		$problem = array_merge($problem, ["'", '"', '^', '?', '\\', '/', ',', ';']);
+		$replace = array_merge($replace, ["’", '"', '^', '?', '\', '/', ',', ';']);
 	}
 
 	return trim(str_replace($problem, $replace, $text));

+ 6 - 0
tests/lib/LibRssTest.php

@@ -87,4 +87,10 @@ final class LibRssTest extends \PHPUnit\Framework\TestCase {
 				'<?pi <img loading="lazy" title="?><p title=" src="u.png">'],
 		];
 	}
+
+	public function test_escapeToUnicodeAlternative(): void {
+		self::assertSame('a&b<c>d\'"^?', escapeToUnicodeAlternative('a&b<c>d\'"^?', false));
+		self::assertSame('a’b"c^d?e\f/g,h;i', escapeToUnicodeAlternative('a\'b"c^d?e\\f/g,h;i', true));
+		self::assertSame('&<>’"^?\/,;', escapeToUnicodeAlternative('&<>\'"^?\\/,;', true));
+	}
 }