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

Error: Incorrectly eaten value #463

Closed
APixelVisuals opened this issue Jan 7, 2020 · 3 comments
Closed

Error: Incorrectly eaten value #463

APixelVisuals opened this issue Jan 7, 2020 · 3 comments

Comments

@APixelVisuals
Copy link

@APixelVisuals APixelVisuals commented Jan 7, 2020

Incorrectly eaten value

I got an error while extending the remark-parse parser:

Error: Incorrectly eaten value: please report this warning on https://git.io/vg5Ft
    at validateEat (/home/apixel/Documents/project/node_modules/remark-parse/lib/tokenizer.js:147:11)
    at eat (/home/apixel/Documents/project/node_modules/remark-parse/lib/tokenizer.js:232:7)
    at Of.remarkParse.Parser.inlineTokenizers.userTag (/home/apixel/Documents/project/modules/misc/Image.js:12:28)
    at Of.tokenize [as tokenizeInline] (/home/apixel/Documents/project/node_modules/remark-parse/lib/tokenizer.js:58:18)
    at Of.paragraph (/home/apixel/Documents/project/node_modules/remark-parse/lib/tokenize/paragraph.js:115:20)
    at Of.tokenize [as tokenizeBlock] (/home/apixel/Documents/project/node_modules/remark-parse/lib/tokenizer.js:58:18)
    at Of.parse (/home/apixel/Documents/project/node_modules/remark-parse/lib/parse.js:33:20)
    at Function.parse (/home/apixel/Documents/project/node_modules/unified/index.js:271:45)
    at Image.markdownText (/home/apixel/Documents/project/modules/misc/Image.js:94:36)
    at module.exports (/home/apixel/Documents/project/modules/messageImage.js:45:36)

Environment

  • OS: Linux Mint 19.1 Cinnamon
  • Packages: remark-parse v7.0.2, unified v8.4.2
  • Env: Node.js v10.18.0, NPM v6.13.4

Steps to reproduce

const remarkParse = require("remark-parse");

remarkParse.Parser.prototype.inlineTokenizers.userTag = (eat, value, silent) => {

    const match = /<@!?[0-9]+>/.exec(value);

    if ((match) && (silent)) return true;
    else if (match) return eat(match[0])({
        type: "userTag",
        children: [{ type: "text", value: match[0].replace(/[<>@!]/g, "") }]
    });
};
remarkParse.Parser.prototype.inlineTokenizers.userTag.locator = (value, fromIndex) => value.indexOf("<", fromIndex);
remarkParse.Parser.prototype.inlineMethods.splice(remarkParse.Parser.prototype.inlineMethods.indexOf("text"), 0, "userTag");

const markdownParser = require("unified")().use(remarkParse);

markdownParser.parse("asd asd <@!196795781410324480> asdasd")

Expected behavior

<@!196795781410324480> should be parsed as a userTag.

Actual behavior

I get the error above.

@APixelVisuals

This comment has been minimized.

Copy link
Author

@APixelVisuals APixelVisuals commented Jan 7, 2020

Misclicked, sorry

@ChristianMurphy

This comment has been minimized.

Copy link
Member

@ChristianMurphy ChristianMurphy commented Jan 7, 2020

@APixelVisuals the value is correctly eaten, you need guard statements to ensure the value you are looking for matches your expected pattern.
See https://github.com/remarkjs/remark/blob/master/packages/remark-parse/lib/tokenize/html-inline.js for an example.

In your case the guard could look something like:

if (
  value.charAt(0) !== "<" ||
  value.charAt(1) !== "@" ||
  value.charAt(2) !== "!" ||
  value.length < 5
) {
  return;
}

add it anywhere inside the userTag function before eat is called.

@APixelVisuals

This comment has been minimized.

Copy link
Author

@APixelVisuals APixelVisuals commented Jan 7, 2020

Thanks for the help, everything is working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.