-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Weird bug with pruneLength and Chinese text #22390
Comments
Apparently this is a bug in the module.exports = function prune(str, length, pruneStr) {
str = makeString(str);
length = ~~length;
pruneStr = pruneStr != null ? String(pruneStr) : '...';
if (str.length <= length) return str;
var tmpl = function(c) {
return c.toUpperCase() !== c.toLowerCase() ? 'A' : ' ';
},
template = str.slice(0, length + 1).replace(/.(?=\W*\w*$)/g, tmpl); // 'Hello, world' -> 'HellAA AAAAA'
if (template.slice(template.length - 2).match(/\w\w/))
template = template.replace(/\s*\S+$/, '');
else
template = rtrim(template.slice(0, template.length - 1));
return (template + pruneStr).length > str.length ? str : str.slice(0, template.length) + pruneStr;
}; The particular line |
@jlkiri thanks.. hopefully your fix will get merged soon! |
@lucasholder Can you confirm whether this PR fixed your issue? |
Going to close this due to lack of response. If this is still the case please reopen or open a new issue pointing to this issue. Thanks! |
Description
When the Chinese text in a MDX file is too long,
excerpt(pruneLength: 250)
returns an empty string. When the text is a bit shorter, it returns the expected string of length 250.Steps to reproduce
I'm a gatsby noob, not sure how to make a smaller reproduction of the bug... Basically, I did
gatsby new gatsby-prunelength-bug https://github.com/vim-labs/gatsby-theme-sky-lite-starter
and changed last 2 blog posts, one with long Chinese text and other with shorter Chinese text. Here's the guilty line: https://github.com/vim-labs/gatsby-theme-sky-lite/blob/master/src/templates/home.js#L139Environment
The text was updated successfully, but these errors were encountered: