Fix util.getStringWidth for falsy input (#3092)

master
Lucas Azzola 2017-10-24 15:19:27 +11:00 committed by GitHub
parent c0aaa0fa52
commit 1d3c86be4d
4 changed files with 22 additions and 0 deletions

View File

@ -740,6 +740,10 @@ function splitText(text) {
}
function getStringWidth(text) {
if (!text) {
return 0;
}
// emojis are considered 2-char width for consistency
// see https://github.com/sindresorhus/string-width/issues/11
// for the reason why not implemented in `string-width`

View File

@ -33,6 +33,19 @@ exports[`emoji.md 1`] = `
`;
exports[`empty.md 1`] = `
Foo | Bar
--- | ---
X |
Y |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Foo | Bar |
| --- | --- |
| X |
| Y |
`;
exports[`escape.md 1`] = `
| a | b | c |
|:--|:-:|--:|

View File

@ -0,0 +1,4 @@
Foo | Bar
--- | ---
X |
Y |

View File

@ -18,6 +18,7 @@ function run_spec(dirname, options, additionalParsers) {
if (
extname(filename) !== ".snap" &&
fs.lstatSync(path).isFile() &&
filename[0] !== "." &&
filename !== "jsfmt.spec.js"
) {
let rangeStart = 0;