diff --git a/src/parsers/string.ts b/src/parsers/string.ts index c792ee9..813a4c1 100644 --- a/src/parsers/string.ts +++ b/src/parsers/string.ts @@ -11,7 +11,7 @@ import { size } from '@utils/unicode' export function string(match: string): Parser { return { parse(input, pos) { - const nextPos = pos + match.length + const nextPos = Math.min(pos + match.length, input.length) const slice = input.substring(pos, nextPos) switch (slice === match) { @@ -45,7 +45,7 @@ export function string(match: string): Parser { export function ustring(match: string): Parser { return { parse(input, pos) { - const nextPos = pos + size(match) + const nextPos = Math.min(pos + size(match), input.length) const slice = input.substring(pos, nextPos) switch (slice === match) {