From d7602ed38ae76377ad18cfeac9339775c2e30a3b Mon Sep 17 00:00:00 2001 From: mcanam Date: Mon, 29 Apr 2024 03:49:57 +0700 Subject: [PATCH] refactor(parser): improve input validation and error handling --- src/parser.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/parser.js b/src/parser.js index f7443b5..2b3a3e6 100644 --- a/src/parser.js +++ b/src/parser.js @@ -16,16 +16,17 @@ const ENHANCED_REGEX = /<\d{2}:\d{2}(.\d{2,})?>\s*[^\s|<]*/g; * @returns {Object} parsed lrc data */ export default function parser(lrc) { - if (lrc == '' || !lrc.trim()) { - console.warn("[Liricle] LRC is empty."); - } - const output = { tags : {}, lines: [], enhanced: isEnhanced(lrc) }; + if (typeof lrc != 'string' || !lrc.trim()) { + console.warn("[Liricle] LRC is empty."); + return output; + } + const lines = lrc.split(/\r?\n/); // parsing started