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 when article name is a UTF-8 string or contains some UTF-8 characters #11

Open
zwcloud opened this issue May 25, 2015 · 0 comments
Assignees
Labels

Comments

@zwcloud
Copy link

zwcloud commented May 25, 2015

When article name is a UTF-8 string or contains some UTF-8 characters,

gajus.contents.id(articleName)

will return a empty string, which leads to the Error('Invalid ID.')

My temporary solution:
Implement the function contents.formatId like below

contents.formatId = function (str) {
    if (!str.match(/^[a-z]+[a-z0-9\-_:\.]*$/)) {
        return "hash" + str.hashCode();
    }
};

Then gajus/contents works perfectly.

PS:
The implementation of str.hashCode()

String.prototype.hashCode = function () {
    var hash = 0, i, chr, len;
    if (this.length == 0) return hash;
    for (i = 0, len = this.length; i < len; i++) {
        chr = this.charCodeAt(i);
        hash = ((hash << 5) - hash) + chr;
        hash |= 0; // Convert to 32bit integer
    }
    return hash;
};
@gajus gajus self-assigned this May 25, 2015
@gajus gajus added the bug label May 25, 2015
zwcloud added a commit to zwcloud/contents that referenced this issue Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants