diff --git a/CHANGELOG.md b/CHANGELOG.md index e55ec39..3a82871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.2.1] - 2018-05-10 +### Changed +- Fix parsing of the text with the new line and whitespace at the end #25 + ## [1.2.0] - 2018-03-07 ### Added - `toVttTime` and `stringifyVtt` functions #24 diff --git a/dist/subtitle.bundle.js b/dist/subtitle.bundle.js index 85a98b1..4d4b8d8 100644 --- a/dist/subtitle.bundle.js +++ b/dist/subtitle.bundle.js @@ -391,7 +391,7 @@ function parse(srtOrVtt) { return captions; } - if (row.trim() === '') { + if (row === '') { delete caption.index; if (index !== source.length - 1) { captions.push({}); diff --git a/lib/parse.js b/lib/parse.js index f72bde6..5e56242 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -36,7 +36,7 @@ export default function parse (srtOrVtt) { return captions } - if (row.trim() === '') { + if (row === '') { delete caption.index if (index !== source.length - 1) { captions.push({}) diff --git a/package.json b/package.json index e9a3dc5..39a3b46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "subtitle", - "version": "1.2.0", + "version": "1.2.1", "description": "Parse and manipulate SRT (SubRip)", "repository": { "type": "git", diff --git a/test/parse.test.js b/test/parse.test.js index fce61f8..301321b 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -120,3 +120,30 @@ Hi. t.deepEqual(value, expected) }) + +test('parse text that contains only empty space', t => { + const srt = ` +1 +00:00:00,000 --> 00:00:00,100 +Something something something... dark side + + +2 +00:00:00,100 --> 00:00:00,200 +Hi.` + const value = parse(srt) + const expected = [ + { + start: 0, + end: 100, + text: 'Something something something... dark side\n ' + }, { + start: 100, + end: 200, + text: 'Hi.' + } + ] + + t.deepEqual(value, expected) +}) +