Skip to content

Commit

Permalink
#25 valid new line with whitespace (#26)
Browse files Browse the repository at this point in the history
* Don't trim the whitespace

* Add changelog

* Update the build
  • Loading branch information
abdulrahmancz authored and gsantiago committed Jun 22, 2018
1 parent 879b609 commit af0af67
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dist/subtitle.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function parse(srtOrVtt) {
return captions;
}

if (row.trim() === '') {
if (row === '') {
delete caption.index;
if (index !== source.length - 1) {
captions.push({});
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subtitle",
"version": "1.2.0",
"version": "1.2.1",
"description": "Parse and manipulate SRT (SubRip)",
"repository": {
"type": "git",
Expand Down
27 changes: 27 additions & 0 deletions test/parse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit af0af67

Please sign in to comment.