Comments (3)
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.
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.
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)
- `regexNull`: `\08` / `\09`
- Add `regenerate.prototype.remove(fn)`
- Optimize `regenerate.prototype.removeRange`
- Constants for the ranges “BMP code point”, “lead surrogate”, “tail surrogate” HOT 2
- Improve performance / decrease memory usage HOT 3
- Avoid `Array#splice` where possible
- Avoid overhead of calling `dataFromCodePoints()` etc. internally HOT 1
- JavaScript identifier generation script broken since rewrite HOT 3
- Script to convert any Regenerate set to code that generates it
- Bug in `.remove(set)`? HOT 1
- Write a fuzzer to try and find more bugs
- Reduce file size to use it as a RegExp polyfill HOT 1
- Matching lone surrogates *only* HOT 3
- Add option to output ES6 `u`-compatible patterns
- isArray is not using the native isArray method, causing incompatibilities with prototype.js
- Invert regular expression? HOT 1
- Non-minimal regex when adding a second range lower than the first HOT 1
- Incorrect optimization in surrogateMappings HOT 2
- Corrupted file on NPM repo: [email protected] file: regenerate.js
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from regenerate.