Skip to content

Commit 478aaf9

Browse files
committed
Force unorm shim when String.prototype.normalize is broken (ethers-io#338).
1 parent fad902b commit 478aaf9

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

dist/shims.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ function taskBundle(name, options) {
152152
if (options.minify) {
153153
result = result.pipe(buffer())
154154
.pipe(sourcemaps.init({ loadMaps: true }))
155-
.pipe(uglify())
155+
.pipe(uglify({
156+
output: { ascii_only: true }
157+
}))
156158
.pipe(sourcemaps.write('./'))
157159
}
158160

@@ -190,7 +192,9 @@ gulp.task('shims', function () {
190192
.bundle()
191193
.pipe(source('shims.js'))
192194
.pipe(buffer())
193-
.pipe(uglify())
195+
.pipe(uglify({
196+
output: { ascii_only: true }
197+
}))
194198
.pipe(gulp.dest('dist'));
195199

196200
return result;
@@ -287,7 +291,9 @@ function taskLang(locale) {
287291
.bundle()
288292
.pipe(source("wordlist-" + locale + ".js"))
289293
.pipe(buffer())
290-
.pipe(uglify())
294+
.pipe(uglify({
295+
output: { ascii_only: true }
296+
}))
291297
.pipe(gulp.dest("dist"));
292298
});
293299
}

tests/shims/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
'use strict';
22

33
// Shim String.prototype.normalize
4-
var unorm = require('./unorm.js');
4+
try {
5+
// Some platforms have a native normalize, but it is broken; so we force our shim
6+
if (String.fromCharCode(0xe9).normalize('NFD') !== String.fromCharCode(0x65, 0x0301)) {
7+
throw new Error('bad normalize');
8+
}
9+
} catch (error) {
10+
var unorm = require('./unorm.js');
11+
console.log("Broken String.prototype.normalize... Forcing shim.");
12+
String.prototype.normalize = function(form) {
13+
var func = unorm[(form || 'NFC').toLowerCase()];
14+
if (!func) { throw new RangeError('invalid form - ' + form); }
15+
return func(this);
16+
}
17+
}
518

619
// Shim atob and btoa
720
var base64 = require('./base64.js');

0 commit comments

Comments
 (0)