fengari icon indicating copy to clipboard operation
fengari copied to clipboard

string.format() doesn't work under IE 11

Open Egor-Skriptunoff opened this issue 6 years ago • 11 comments
trafficstars

Fengari is said to be "Verified to work in Microsoft IE 11". But unfortunately an error is raised under IE 11:

print(("%02X"):format(0)) TypeError: Object doesn't support property or method 'repeat'

fengari_ie11

It seems that the sprintf.js which implements string.format is not IE11-compatible. The problem is in the single line of code:

pad = ph.width ? (pad_length > 0 ? pad_character.repeat(pad_length) : '') : ''

Unfortunately, repeat is not implemented on all IE, including IE11

BTW .repeat occurs also in lstrlib.js.

Support of IE11 actually means support of Windows 7 users. There are a lot of them nowadays.

All what is needed for happiness is to implement String.prototype.repeat manually in Fengari.

Egor-Skriptunoff avatar Feb 26 '19 20:02 Egor-Skriptunoff

Note to self: see core-js implementation https://github.com/zloirock/core-js/blob/master/packages/core-js/internals/string-repeat.js#L12

daurnimator avatar Feb 26 '19 21:02 daurnimator

Filed https://github.com/alexei/sprintf.js/issues/182 Also see #149

daurnimator avatar Mar 11 '19 13:03 daurnimator

I can't modify the global environment

But why? Defining standard well-known (but undefined on IE) function looks very innocent.

Egor-Skriptunoff avatar Mar 11 '19 21:03 Egor-Skriptunoff

I've worked in environments before where the rule is never modify the global JS environment. I want fengari to be allowed in such environments.

Every modification you make is potentially conflicting with some other piece of JS running on a site. The easiest solution is to just opt out.

daurnimator avatar Mar 12 '19 04:03 daurnimator

Probably, this issue should be migrated from fengari to fengari-web, because it affects only fengari running inside browser.

Egor-Skriptunoff avatar Mar 12 '19 06:03 Egor-Skriptunoff

The bug hasn't been solved in three months. Maybe, the documentation should honestly claim that Fengari does require a polyfill for IE11?

Egor-Skriptunoff avatar Jun 07 '19 06:06 Egor-Skriptunoff

I've been hoping that https://github.com/alexei/sprintf.js/pull/183 will get merged. Otherwise I may just remove that dependency entirely and implement our own sprintf-alike.

daurnimator avatar Jun 07 '19 06:06 daurnimator

I haven't had the time to implement out own sprintf, so I'm marking this issue as "help-wanted". If anyone would like to implement it, please send a PR!

daurnimator avatar Aug 14 '19 13:08 daurnimator

Would it be fine just to fork + vendor sprintf.js with your fix?

catwell avatar Aug 16 '19 07:08 catwell

Would it be fine just to fork + vendor sprintf.js with your fix?

I guess. But there is plenty of code in there we don't use. And the verification code in lstrlib.js sort of duplicates some of the work anyway. A rewrite with a bit of "inspiration" is probably the best choice.

daurnimator avatar Aug 16 '19 07:08 daurnimator

I can't modify the global environment

But why? Defining standard well-known (but undefined on IE) function looks very innocent.

You pollute users namespace. It's considered a bad practice. It's much easier to point users that it's not working on this and that browser and offer a link to a polyfill - if user wants then can include polyfil from separate repo - but then it's extra request or extra job to bake it into users code.

There is a way to create a copy of String prototype and assign it to new class - OurString and decorate it encapsulated only in module scope. @daurnimator what do you think?


or https://github.com/alexei/sprintf.js/pull/193

ashwalk33r avatar Apr 02 '20 21:04 ashwalk33r