Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header-Parser exception #39

Closed
McBen opened this issue Nov 23, 2020 · 3 comments
Closed

Header-Parser exception #39

McBen opened this issue Nov 23, 2020 · 3 comments

Comments

@McBen
Copy link
Contributor

McBen commented Nov 23, 2020

const key = sp[1].replace("@", "");

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
Copy link
Contributor Author

McBen commented Nov 23, 2020

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);
}

modos189 added a commit that referenced this issue Aug 23, 2021
modos189 added a commit that referenced this issue Aug 23, 2021
modos189 added a commit that referenced this issue Aug 23, 2021
@modos189
Copy link
Contributor

Made a fix based on your code. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants