Преглед на файлове

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 часа
родител
ревизия
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
 	// https://raw.githubusercontent.com/mihaip/google-reader-api/master/wiki/StreamId.wiki
 	if ($extended) {
 	if ($extended) {
-		$problem += ["'", '"', '^', '?', '\\', '/', ',', ';'];
-		$replace += ["’", '"', '^', '?', '\', '/', ',', ';'];
+		$problem = array_merge($problem, ["'", '"', '^', '?', '\\', '/', ',', ';']);
+		$replace = array_merge($replace, ["’", '"', '^', '?', '\', '/', ',', ';']);
 	}
 	}
 
 
 	return trim(str_replace($problem, $replace, $text));
 	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">'],
 				'<?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));
+	}
 }
 }