fix(diag): Video-IDs ohne Ziffern und Titel/Namen in JSON-Zeilen entfernen
Gleiche Regel wie PC und Server (playtube-jam/src/diag.js). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -20,14 +20,20 @@ object DiagReport {
|
||||
private val EMAIL = Regex("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
|
||||
private val URL_QUERY = Regex("(?i)(https?://[^\\s?#\"']+)[?#][^\\s\"']*")
|
||||
private val WORD = Regex("[A-Za-z0-9_-]+")
|
||||
private val JSON_PRIVATE = Regex("(?i)(\"(?:title|artist|author|album|name|query|q|search)\"\\s*:\\s*)\"(?:[^\"\\\\]|\\\\.)*\"")
|
||||
private val CAMEL = Regex("^([A-Z][a-z]+)+$")
|
||||
private val CONTROL = Regex("[\\u0000-\\u0008\\u000b-\\u001f\\u007f\\u202a-\\u202e\\u2066-\\u2069]")
|
||||
|
||||
/** YouTube-Video-ID: 11 Zeichen, Gross- und Kleinbuchstaben gemischt plus Ziffer, `_` oder `-`. */
|
||||
fun looksLikeVideoId(word: String): Boolean =
|
||||
word.length == 11 &&
|
||||
word.all { it.isLetterOrDigit() && it.code < 128 || it == '_' || it == '-' } &&
|
||||
word.any { it in 'A'..'Z' } && word.any { it in 'a'..'z' } &&
|
||||
word.any { it.isDigit() || it == '_' || it == '-' }
|
||||
/**
|
||||
* YouTube-Video-ID: 11 Zeichen aus `[A-Za-z0-9_-]`, entweder Buchstaben plus Ziffer/`_`/`-` oder
|
||||
* mindestens zwei Grossbuchstaben ohne normale Schreibweise (nicht "Verbindunge", "ServerError").
|
||||
*/
|
||||
fun looksLikeVideoId(word: String): Boolean {
|
||||
if (word.length != 11 || !word.all { it in 'A'..'Z' || it in 'a'..'z' || it in '0'..'9' || it == '_' || it == '-' }) return false
|
||||
val letters = word.any { it.isLetter() }
|
||||
if (word.any { it.isDigit() || it == '_' || it == '-' }) return letters
|
||||
return word.count { it in 'A'..'Z' } >= 2 && word.any { it in 'a'..'z' } && !CAMEL.matches(word)
|
||||
}
|
||||
|
||||
private fun looksLikeSecret(word: String): Boolean =
|
||||
word.length >= 20 && word.any { it.isDigit() } && word.any { it.isLetter() }
|
||||
@@ -39,6 +45,7 @@ object DiagReport {
|
||||
text = SECRET.replace(text) { "${it.groupValues[1]}${it.groupValues[2]}[entfernt]" }
|
||||
text = EMAIL.replace(text, "[e-mail]")
|
||||
text = URL_QUERY.replace(text) { "${it.groupValues[1]}?[…]" }
|
||||
text = JSON_PRIVATE.replace(text) { "${it.groupValues[1]}\"[entfernt]\"" }
|
||||
text = WORD.replace(text) {
|
||||
when {
|
||||
looksLikeVideoId(it.value) -> "[video]"
|
||||
|
||||
@@ -23,6 +23,16 @@ class DiagReportTest {
|
||||
assertEquals("a b", DiagReport.sanitize("a\u0000b"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removesIdsWithoutDigitsAndJsonTitles() {
|
||||
assertEquals("jam: lade [video]", DiagReport.sanitize("jam: lade JZYXtUJcTws"))
|
||||
assertEquals(
|
||||
"Player: {\"artist\":\"[entfernt]\",\"id\":\"[video]\",\"title\":\"[entfernt]\",\"paused\":true}",
|
||||
DiagReport.sanitize("Player: {\"artist\":\"Band\",\"id\":\"Rlg9P5i1bkQ\",\"title\":\"Mein Song\",\"paused\":true}"),
|
||||
)
|
||||
assertEquals("Verbindunge ServerError PlaytubeApp", DiagReport.sanitize("Verbindunge ServerError PlaytubeApp"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun recognizesVideoIds() {
|
||||
assertTrue(DiagReport.looksLikeVideoId("dQw4w9WgXcQ"))
|
||||
|
||||
Reference in New Issue
Block a user