mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-20 16:49:52 +00:00
Update Regex, add pledit with quotes
This commit is contained in:
parent
eaf1bbe5c9
commit
5732baeb97
3 changed files with 22 additions and 1 deletions
6
js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT
Normal file
6
js/__tests__/fixtures/PLEDIT_WITH_QUOTES.TXT
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[Text]
|
||||
Normal= "#00FF00"
|
||||
Current= '#FFFFFF'
|
||||
NormalBG= "#000000"
|
||||
SelectedBG= "#0000FF"
|
||||
Font= "Ricky's cool font!"
|
||||
|
|
@ -78,7 +78,7 @@ export const parseIni = text => {
|
|||
let section, match;
|
||||
return text.split(/[\r\n]+/g).reduce((data, line) => {
|
||||
if ((match = line.match(PROPERTY_REGEX)) && section != null) {
|
||||
const value = match[2].replace(/("|')/gi, "");
|
||||
const value = match[2].replace(/(^")|("$)|(^')|('$)/gi, "");
|
||||
data[section][match[1].trim().toLowerCase()] = value;
|
||||
} else if ((match = line.match(SECTION_REGEX))) {
|
||||
section = match[1].trim().toLowerCase();
|
||||
|
|
|
|||
|
|
@ -145,6 +145,21 @@ bar = baz
|
|||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("can parse a pledit.txt file with quotes", () => {
|
||||
const pledit = fixture("PLEDIT_WITH_QUOTES.TXT");
|
||||
const actual = parseIni(pledit);
|
||||
const expected = {
|
||||
text: {
|
||||
normal: "#00FF00",
|
||||
current: "#FFFFFF",
|
||||
normalbg: "#000000",
|
||||
selectedbg: "#0000FF",
|
||||
font: "Ricky's cool font!"
|
||||
}
|
||||
};
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("allows quotes around values", () => {
|
||||
const actual = parseIni(`
|
||||
[foo]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue