Skip to content

Commit

Permalink
5.2.7: Fix TypeError when translation is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
kirainmoe committed Sep 2, 2017
1 parent 86eb8a7 commit 6565b0c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion dist/assets/muse-player-react-lite.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/assets/muse-player.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muse-player",
"version": "5.2.6",
"version": "5.2.7",
"description": "Just a simple and dilligent HTML5 Audio Player written in React.",
"main": "dist/assets/muse-player.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

// Settings configured here will be merged into the final config object.
export default {
MUSE_VERSION: '5.2.6'
MUSE_VERSION: '5.2.7'
}
65 changes: 35 additions & 30 deletions src/utils/lyricParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const lyricParser = (rawLyric, rawTranslation) => {
if (!raw || typeof raw != 'string') {
return false;
}
if (rawTranslation.match(/\[(\d{1,2}):(\d|[0-5]\d)(\.\d+)?\]/)) {

if (
rawTranslation &&
rawTranslation.match(/\[(\d{1,2}):(\d|[0-5]\d)(\.\d+)?\]/)
) {
transVersion = 1;
}
// simplified version of lyric: [time1][time2]lyric
Expand Down Expand Up @@ -83,38 +87,39 @@ export const lyricParser = (rawLyric, rawTranslation) => {
});

/* Translation parse block */
rawTranslation = rawTranslation.replace(/\\n/g, '\n').replace(/\\r/g, '\r');

lines = String(rawTranslation).split('\n');
lines.forEach(index => {
if (index.match(/\[ti:|ar:|al:\.*]/g)) return;

// translation author
if (index.match(/\[by:(.*)\]/g)) {
res.transAuthor = /\[by:(.*)\]/g.exec(index)[1];
return;
}
if (rawTranslation) {
rawTranslation = rawTranslation.replace(/\\n/g, '\n').replace(/\\r/g, '\r');

lines = String(rawTranslation).split('\n');
lines.forEach(index => {
if (index.match(/\[ti:|ar:|al:\.*]/g)) return;

// translation author
if (index.match(/\[by:(.*)\]/g)) {
res.transAuthor = /\[by:(.*)\]/g.exec(index)[1];
return;
}

switch (transVersion) {
// lines
case 0:
transArr.push(index);
break;

switch (transVersion) {
// lines
case 0:
transArr.push(index);
break;
// simplified
case 1:
if (!index) break;

// simplified
case 1:
if (!index)
const match = /\[(\d{1,2}):(\d|[0-5]\d)(\.\d+)?\](.*)/g.exec(index),
timeline = calcTime(match);
transArr.push({
timeline: timeline,
text: match[4]
});
break;

const match = /\[(\d{1,2}):(\d|[0-5]\d)(\.\d+)?\](.*)/g.exec(index),
timeline = calcTime(match);
transArr.push({
timeline: timeline,
text: match[4]
});
break;
}
});
}
});
}

// sort lyrics
const cmp = (a, b) => a.timeline - b.timeline;
Expand Down

0 comments on commit 6565b0c

Please sign in to comment.