Greasemonkey: Fix metadata block regex.
This regex was broken since the original PR and subsequent code seemed to be working around it. Before re.split was returning [everything up to /UserScript, everything else], now it returns [before UserScript, metadata, after /UserScript], which is good. Also I added the check for the UserScript line starting at column 0 as per spec.
This commit is contained in:
parent
5e49e7eef2
commit
d318178567
@ -60,7 +60,7 @@ class GreasemonkeyScript:
|
|||||||
elif name == 'run-at':
|
elif name == 'run-at':
|
||||||
self.run_at = value
|
self.run_at = value
|
||||||
|
|
||||||
HEADER_REGEX = r'// ==UserScript==.|\n+// ==/UserScript==\n'
|
HEADER_REGEX = r'// ==UserScript==|\n+// ==/UserScript==\n'
|
||||||
PROPS_REGEX = r'// @(?P<prop>[^\s]+)\s+(?P<val>.+)'
|
PROPS_REGEX = r'// @(?P<prop>[^\s]+)\s+(?P<val>.+)'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -71,13 +71,13 @@ class GreasemonkeyScript:
|
|||||||
Parses the greasemonkey metadata block, if present, to fill out
|
Parses the greasemonkey metadata block, if present, to fill out
|
||||||
attributes.
|
attributes.
|
||||||
"""
|
"""
|
||||||
matches = re.split(cls.HEADER_REGEX, source, maxsplit=1)
|
matches = re.split(cls.HEADER_REGEX, source, maxsplit=2)
|
||||||
try:
|
try:
|
||||||
props, _code = matches
|
_, props, _code = matches
|
||||||
except ValueError:
|
except ValueError:
|
||||||
props = ""
|
props = ""
|
||||||
script = cls(re.findall(cls.PROPS_REGEX, props), source)
|
script = cls(re.findall(cls.PROPS_REGEX, props), source)
|
||||||
script.script_meta = '"{}"'.format("\\n".join(props.split('\n')[2:]))
|
script.script_meta = props
|
||||||
if not props:
|
if not props:
|
||||||
script.includes = ['*']
|
script.includes = ['*']
|
||||||
return script
|
return script
|
||||||
|
Loading…
Reference in New Issue
Block a user