Force unorm shim when String.prototype.normalize is broken (#338).

This commit is contained in:
Richard Moore 2018-11-09 14:36:21 -05:00
parent fad902b438
commit 478aaf9619
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
3 changed files with 24 additions and 5 deletions

2
dist/shims.js vendored

File diff suppressed because one or more lines are too long

View File

@ -152,7 +152,9 @@ function taskBundle(name, options) {
if (options.minify) {
result = result.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(uglify({
output: { ascii_only: true }
}))
.pipe(sourcemaps.write('./'))
}
@ -190,7 +192,9 @@ gulp.task('shims', function () {
.bundle()
.pipe(source('shims.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(uglify({
output: { ascii_only: true }
}))
.pipe(gulp.dest('dist'));
return result;
@ -287,7 +291,9 @@ function taskLang(locale) {
.bundle()
.pipe(source("wordlist-" + locale + ".js"))
.pipe(buffer())
.pipe(uglify())
.pipe(uglify({
output: { ascii_only: true }
}))
.pipe(gulp.dest("dist"));
});
}

View File

@ -1,7 +1,20 @@
'use strict';
// Shim String.prototype.normalize
try {
// Some platforms have a native normalize, but it is broken; so we force our shim
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
throw new Error('bad normalize');
}
} catch (error) {
var unorm = require('./unorm.js');
console.log("Broken String.prototype.normalize... Forcing shim.");
String.prototype.normalize = function(form) {
var func = unorm[(form || 'NFC').toLowerCase()];
if (!func) { throw new RangeError('invalid form - ' + form); }
return func(this);
}
}
// Shim atob and btoa
var base64 = require('./base64.js');