From e3c534c56921c50e94d27fd15e880667c92ee1b0 Mon Sep 17 00:00:00 2001 From: fojadrachi Date: Sat, 14 Nov 2026 00:02:47 +0100 Subject: [PATCH] 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 --- .../java/de/fojadrachi/playtube/DiagReport.kt | 19 +++++++++++++------ .../de/fojadrachi/playtube/DiagReportTest.kt | 10 ++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/fojadrachi/playtube/DiagReport.kt b/app/src/main/java/de/fojadrachi/playtube/DiagReport.kt index bddc1f2..563008a 100644 --- a/app/src/main/java/de/fojadrachi/playtube/DiagReport.kt +++ b/app/src/main/java/de/fojadrachi/playtube/DiagReport.kt @@ -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]" diff --git a/app/src/test/java/de/fojadrachi/playtube/DiagReportTest.kt b/app/src/test/java/de/fojadrachi/playtube/DiagReportTest.kt index a6a2942..e02f6ab 100644 --- a/app/src/test/java/de/fojadrachi/playtube/DiagReportTest.kt +++ b/app/src/test/java/de/fojadrachi/playtube/DiagReportTest.kt @@ -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"))