IITC-CE / IITC-Button

Firefox/Chrome extensions that enables IITC features
GNU General Public License v3.0
16 stars 6 forks source link

Header-Parser exception #39

Closed McBen closed 3 years ago

McBen commented 3 years ago

https://github.com/IITC-CE/IITC-Button/blob/d8b5d8be1c1314fbfcfa712727989114cae41f0d/src/helpers.js#L26

will fail if line is empty

like:

// @download sdfsdf

// @author sdfsdf

/edit additional: a missing space between // and @ is also accepted by tampermonkey but not by iitc-button //@author sdfsdf

McBen commented 3 years ago

maybe use some regex instead of manual parsing?

like

var regexHeader = /==UserScript==\s*([\s\S]*)\/\/\s*==\/UserScript==/m  // Note: \s\S to match linebreaks
var regexEntry = /\/\/\s*@(\S+)\s+(.*)$/gm  // example match: "\\ @name some text"

var header = regexHeader.exec(pluginCode);
if (header === null) return;
header = header[1]

var entry = regexEntry.exec(header);
while (entry) {
    console.log(entry[1], " = ", entry[2]); // FIXME: entry[2] should be trimmed and " removed
    entry = regexEntry.exec(header);
}
johnd0e commented 3 years ago

I have another homebrew meta parser here: https://github.com/IITC-CE/ingress-intel-total-conversion/pull/242/files

https://github.com/IITC-CE/ingress-intel-total-conversion/blob/95c6f4d4f4c179b4169d01b3161db068a2aef5c7/core/code/utils_misc.js#L9-L17

modos189 commented 3 years ago

Made a fix based on your code. Thanks