mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Only read up to 100KB
This commit is contained in:
@@ -16,6 +16,9 @@ module Linguist
|
|||||||
new.extract_tokens(data)
|
new.extract_tokens(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Read up to 100KB
|
||||||
|
BYTE_LIMIT = 100_000
|
||||||
|
|
||||||
# Start state on token, ignore anything till the next newline
|
# Start state on token, ignore anything till the next newline
|
||||||
SINGLE_LINE_COMMENTS = [
|
SINGLE_LINE_COMMENTS = [
|
||||||
'//', # C
|
'//', # C
|
||||||
@@ -55,6 +58,8 @@ module Linguist
|
|||||||
|
|
||||||
tokens = []
|
tokens = []
|
||||||
until s.eos?
|
until s.eos?
|
||||||
|
break if s.pos >= BYTE_LIMIT
|
||||||
|
|
||||||
if token = s.scan(/^#!.+$/)
|
if token = s.scan(/^#!.+$/)
|
||||||
if name = extract_shebang(token)
|
if name = extract_shebang(token)
|
||||||
tokens << "SHEBANG#!#{name}"
|
tokens << "SHEBANG#!#{name}"
|
||||||
|
|||||||
Reference in New Issue
Block a user