voltangle / SubtitleKit

Package for creating, modifying, and managing subtitle files, such as SubRip (.srt).
3 stars 0 forks source link

fatal error when srt has several newlines at the end #2

Open Yang-Xijie opened 2 years ago

Yang-Xijie commented 2 years ago

This is OK:

let str = """
1
00:00:00,720 --> 00:00:01,620
some text
"""

let result = try SubRip.parseFile(content: str)
print(result)
[Backend.SubRipNode(index: 1, interval: 1999-12-31 16:00:00 +0000 to 1999-12-31 16:00:01 +0000, text: "some text")]

This is also OK with only one newline:

let str = """
1
00:00:00,720 --> 00:00:01,620
some text

"""

let result = try SubRip.parseFile(content: str)
print(result)
[Backend.SubRipNode(index: 1, interval: 1999-12-31 16:00:00 +0000 to 1999-12-31 16:00:01 +0000, text: "some text\n")]

However, more than two newlines will cause a fatal error:

let str = """
1
00:00:00,720 --> 00:00:01,620
some text

"""

let result = try SubRip.parseFile(content: str)
print(result)

output

Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Backend.SubRipParserError.notFullNodeDeclaration(column: 0, row: 1)
2022-06-20 03:06:58.901269+0800 SrtProcessing[74669:1300033] Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Backend.SubRipParserError.notFullNodeDeclaration(column: 0, row: 1)

Xcode debug 0_swift_runtime_on_report: Thread 1: Fatal error: Error raised at top level: Backend.SubRipParserError.notFullNodeDeclaration(column: 0, row: 1)

libswiftCore.dylib`_swift_runtime_on_report:
->  0x7ff80fecda10 <+0>: pushq  %rbp
    0x7ff80fecda11 <+1>: movq   %rsp, %rbp
    0x7ff80fecda14 <+4>: popq   %rbp
    0x7ff80fecda15 <+5>: retq   
    0x7ff80fecda16 <+6>: nopw   %cs:(%rax,%rax)

macOS 12.4 Xcode 13.4.1

$ swift --version

swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12) Target: x86_64-apple-macosx12.0

SubtitleKit version: a4a97bc1ff79bba54f2d761c87d9468f19ed9d14

Yang-Xijie commented 2 years ago

It should be weird to have newline between two node. However, when it comes to the end of the file, multiple newlines should not be considered a error.

voltangle commented 2 years ago

Oh, someone actually noticed this project, wow well, that is just because the parser is too dumb and not so smart, that can be fixed by handling this edge case