From e685257fbc558855ef89a46afd49ade96eb5db1a Mon Sep 17 00:00:00 2001 From: Aaron Nwabuoku Date: Sun, 9 Jun 2019 12:24:39 -0400 Subject: [PATCH 1/2] Add test for playlist entry element with empty string --- .../kotlin/ru/grushetsky/m3uparser/M3uParserTest.kt | 10 ++++++++++ src/test/resources/entry_with_empty_string.txt | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 src/test/resources/entry_with_empty_string.txt diff --git a/src/test/kotlin/ru/grushetsky/m3uparser/M3uParserTest.kt b/src/test/kotlin/ru/grushetsky/m3uparser/M3uParserTest.kt index 28bed4a..dce0008 100644 --- a/src/test/kotlin/ru/grushetsky/m3uparser/M3uParserTest.kt +++ b/src/test/kotlin/ru/grushetsky/m3uparser/M3uParserTest.kt @@ -103,4 +103,14 @@ class M3uParserTest { assertThat(fileParser.entries().entry_info().size).isEqualTo(2) } + + @Test + fun `entry elements with empty string detected correctly`() { + val entryParser = getParser(getResourceAsString("/entry_with_empty_string.txt")).entry_info() + + assertThat(entryParser.enrty_basic_info().entry_name().text).isEqualTo("Channel 1") + assertThat(entryParser.enrty_basic_info().entry_uri().text).isEqualTo("http://1.2.3.4:1234/udp/4.3.2.1:5678") + assertThat(entryParser.parameters().parameter().size).isEqualTo(4) + assertThat(entryParser.length().text).isEqualTo("-1") + } } \ No newline at end of file diff --git a/src/test/resources/entry_with_empty_string.txt b/src/test/resources/entry_with_empty_string.txt new file mode 100644 index 0000000..688d4e6 --- /dev/null +++ b/src/test/resources/entry_with_empty_string.txt @@ -0,0 +1,3 @@ +#EXTINF:-1 tvg-name="Channel_1" tvg-logo="" +tvg-shift=a0 aspect-ratio=16:9,Channel 1 +http://1.2.3.4:1234/udp/4.3.2.1:5678 \ No newline at end of file From 69910c08305beef5d1d01780a975544246de74f5 Mon Sep 17 00:00:00 2001 From: Aaron Nwabuoku Date: Sun, 9 Jun 2019 12:26:33 -0400 Subject: [PATCH 2/2] Modify M3uLexer.g4 QUOTED_STRING rule to support zero or more quoted tokens --- src/main/antlr/M3uLexer.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/antlr/M3uLexer.g4 b/src/main/antlr/M3uLexer.g4 index 9ffe189..6ca5181 100644 --- a/src/main/antlr/M3uLexer.g4 +++ b/src/main/antlr/M3uLexer.g4 @@ -6,7 +6,7 @@ FILE_START: '#EXTM3U'; CHANNEL_START: EXTINF; NUMBER: '-'? DIGIT+; SAFE_STRING: SAFE_CHAR+; -QUOTED_STRING: QUOTE (SAFE_CHAR | NUMBER | COLON | EQUALS | SPACES | COMMA)+ QUOTE; +QUOTED_STRING: QUOTE (SAFE_CHAR | NUMBER | COLON | EQUALS | SPACES | COMMA)* QUOTE; COMMA: ',' -> pushMode(CHANNEL_DESC); COLON: ':'; EQUALS: '=';