Git Product home page Git Product logo

Comments (3)

WebReflection avatar WebReflection commented on May 16, 2024

OK, found the gotcha ...

var list = ["9⃣", "8⃣", "7⃣", "6⃣", "5⃣", "4⃣", "3⃣", "2⃣", "1⃣", "0⃣", "#⃣"];
var regenerate = require('regenerate');
var regenerated = regenerate.apply(null, list);
console.log(list.filter(function (chr) {
  return (0 <= chr && chr <= 9) || chr == '#';
}).length ?
  'There should be #0-9 in the RegExp' :
  'There should be NO #0-9 in the RegExp'
);
console.log(regenerated.toRegExp());

from regenerate.

mathiasbynens avatar mathiasbynens commented on May 16, 2024

Regenerate only deals with individual code points or symbols (by design). The problem is list contains strings that contain multiple code points, i.e. the first 21 entries:

"🇨🇳", "🇺🇸", "🇷🇺", "🇰🇷", "🇯🇵", "🇮🇹", "🇬🇧", "🇫🇷", "🇪🇸", "🇩🇪", "9⃣", "8⃣", "7⃣", "6⃣", "5⃣", "4⃣", "3⃣", "2⃣", "1⃣", "0⃣", "#⃣",

I’d suggest you manually create the regexp for those 21 emoji, and have the rest of the regex generated by Regenerate.

from regenerate.

WebReflection avatar WebReflection commented on May 16, 2024

so I guess I should convert those chars upfront and then reparse, right? Thanks. I knew it was me, although a warning or something like "you are doing it wrong with these strings" would have been nicer than a silent success with potentially broken RegExp.

Talking from a parsing security point of view. Will close this anyway.

from regenerate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.