Skip to content

Commit

Permalink
Remove the latin1-wtf8 encoding mode
Browse files Browse the repository at this point in the history
The default has been changed to 'none'. The testsuite has been rebuilt
to reflect this; the encoding modes test in runner.js will still
exercise all available encoding modes.
  • Loading branch information
fstirlitz committed Feb 22, 2020
1 parent fb941d3 commit be3c3ee
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 121 deletions.
21 changes: 1 addition & 20 deletions luaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
// '5.1', '5.2', '5.3').
, luaVersion: '5.1'
// Encoding mode: how to interpret code units higher than U+007F in input
, encodingMode: 'latin1-wtf8'
, encodingMode: 'none'
};

function encodeUTF8(codepoint, highMask) {
Expand Down Expand Up @@ -136,25 +136,6 @@
}

var encodingModes = {
// `latin1-wtf8`: assume input was UTF-8, output AST as if it was interpreted as latin1
'latin1-wtf8': {
fixup: function (s) {
return s.replace(/[\ud800-\udbff][\udc00-\udfff]|[^\x00-\x7f]/g, function (m) {
if (m.length === 1)
return encodeUTF8(m.charCodeAt(0));
return encodeUTF8(0x10000 + (((m.charCodeAt(0) & 0x3ff) << 10) | (m.charCodeAt(1) & 0x3ff)));
});
},
encodeByte: function (value) {
if (value === null)
return '';
return String.fromCharCode(value);
},
encodeUTF8: function (codepoint) {
return encodeUTF8(codepoint);
}
},

// `pseudo-latin1` encoding mode: assume the input was decoded with the latin1 encoding
// WARNING: latin1 does **NOT** mean cp1252 here like in the bone-headed WHATWG standard;
// it means true ISO/IEC 8859-1 identity-mapped to Basic Latin and Latin-1 Supplement blocks
Expand Down
18 changes: 0 additions & 18 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,24 +571,6 @@

suite.addTest('Encoding modes', function () {
var cases = [
{ mode: 'latin1-wtf8', src: '"\\u{0}"', value: '\u0000' },
{ mode: 'latin1-wtf8', src: '"\\u{80}"', value: '\u00c2\u0080' },
{ mode: 'latin1-wtf8', src: '"\\u{d800}"', value: '\u00ed\u00a0\u0080' },
{ mode: 'latin1-wtf8', src: '"\\u{20000}"', value: '\u00f0\u00a0\u0080\u0080' },
{ mode: 'latin1-wtf8', src: '"\\x80"', value: '\u0080' },
{ mode: 'latin1-wtf8', src: '"\\x61"', value: 'a' },
{ mode: 'latin1-wtf8', src: '"\\128"', value: '\u0080' },
{ mode: 'latin1-wtf8', src: '"\uf780"', value: '\u00ef\u009e\u0080' },
{ mode: 'latin1-wtf8', src: '"\ud800"', value: '\u00ed\u00a0\u0080' },
{ mode: 'latin1-wtf8', src: '"\u0080"', value: '\u00c2\u0080' },
{ mode: 'latin1-wtf8', src: '[[\uf780]]', value: '\u00ef\u009e\u0080' },
{ mode: 'latin1-wtf8', src: '[[\ud800]]', value: '\u00ed\u00a0\u0080' },
{ mode: 'latin1-wtf8', src: '[[\u0080]]', value: '\u00c2\u0080' },
{ mode: 'latin1-wtf8', src: '"a"', value: 'a' },
{ mode: 'latin1-wtf8', src: '\uf780', name: '\xef\x9e\x80' },
{ mode: 'latin1-wtf8', src: '\x80', name: '\xc2\x80' },
{ mode: 'latin1-wtf8', src: 'a', name: 'a' },

{ mode: 'x-user-defined', src: '"\\u{0}"', value: '\u0000' },
{ mode: 'x-user-defined', src: '"\\u{80}"', value: '\uf7c2\uf780' },
{ mode: 'x-user-defined', src: '"\\u{d800}"', value: '\uf7ed\uf7a0\uf780' },
Expand Down
2 changes: 1 addition & 1 deletion test/spec/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@
},
"argument": {
"type": "StringLiteral",
"value": "",
"value": null,
"raw": "\"\"",
"loc": {
"start": {
Expand Down
42 changes: 21 additions & 21 deletions test/spec/escapesequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"init": [
{
"type": "StringLiteral",
"value": "bar\n\r\t\tbaz",
"value": null,
"raw": "\"bar\\n\\r\\t\tbaz\"",
"loc": {
"start": {
Expand Down Expand Up @@ -159,7 +159,7 @@
"init": [
{
"type": "StringLiteral",
"value": "barPbaz\u0007P\u0000foo",
"value": null,
"raw": "\"bar\\80baz\\a\\80\\0foo\"",
"loc": {
"start": {
Expand Down Expand Up @@ -262,7 +262,7 @@
"init": [
{
"type": "StringLiteral",
"value": "bar\f\u000b\bbaz",
"value": null,
"raw": "\"bar\\f\\v\\bbaz\"",
"loc": {
"start": {
Expand Down Expand Up @@ -365,7 +365,7 @@
"init": [
{
"type": "StringLiteral",
"value": "bar\f\u000b\baz",
"value": null,
"raw": "\"bar\f\u000b\baz\"",
"loc": {
"start": {
Expand Down Expand Up @@ -468,7 +468,7 @@
"init": [
{
"type": "StringLiteral",
"value": "\\",
"value": null,
"raw": "'\\\\'",
"loc": {
"start": {
Expand Down Expand Up @@ -571,7 +571,7 @@
"init": [
{
"type": "StringLiteral",
"value": "'",
"value": null,
"raw": "'\\''",
"loc": {
"start": {
Expand Down Expand Up @@ -674,7 +674,7 @@
"init": [
{
"type": "StringLiteral",
"value": "[",
"value": null,
"raw": "'\\['",
"loc": {
"start": {
Expand Down Expand Up @@ -777,7 +777,7 @@
"init": [
{
"type": "StringLiteral",
"value": "{",
"value": null,
"raw": "'\\123'",
"loc": {
"start": {
Expand Down Expand Up @@ -880,7 +880,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ÿ",
"value": null,
"raw": "'\\255'",
"loc": {
"start": {
Expand Down Expand Up @@ -991,7 +991,7 @@
"init": [
{
"type": "StringLiteral",
"value": "bar\\f\\v\\bbaz",
"value": null,
"raw": "[[bar\\f\\v\\bbaz]]",
"loc": {
"start": {
Expand Down Expand Up @@ -1094,7 +1094,7 @@
"init": [
{
"type": "StringLiteral",
"value": "\\",
"value": null,
"raw": "[[\\]]",
"loc": {
"start": {
Expand Down Expand Up @@ -1197,7 +1197,7 @@
"init": [
{
"type": "StringLiteral",
"value": "z x",
"value": null,
"raw": "'\\z \\x'",
"loc": {
"start": {
Expand Down Expand Up @@ -1311,7 +1311,7 @@
"init": [
{
"type": "StringLiteral",
"value": "#",
"value": null,
"raw": "'\\x23'",
"loc": {
"start": {
Expand Down Expand Up @@ -1454,7 +1454,7 @@
"init": [
{
"type": "StringLiteral",
"value": "barbaz",
"value": null,
"raw": "\"bar\\z baz\"",
"loc": {
"start": {
Expand Down Expand Up @@ -1564,7 +1564,7 @@
"init": [
{
"type": "StringLiteral",
"value": "\u0000",
"value": null,
"raw": "'\\u{0}'",
"loc": {
"start": {
Expand Down Expand Up @@ -1674,7 +1674,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ð\u009f\u0092©",
"value": null,
"raw": "'\\u{1f4a9}'",
"loc": {
"start": {
Expand Down Expand Up @@ -1784,7 +1784,7 @@
"init": [
{
"type": "StringLiteral",
"value": "\u007fÂ\u0080",
"value": null,
"raw": "'\\u{7f}\\u{80}'",
"loc": {
"start": {
Expand Down Expand Up @@ -1894,7 +1894,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ß¿à \u0080",
"value": null,
"raw": "'\\u{7ff}\\u{800}'",
"loc": {
"start": {
Expand Down Expand Up @@ -2004,7 +2004,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ï¿¿ð\u009f\u0092©",
"value": null,
"raw": "'\\u{ffff}\\u{1f4a9}'",
"loc": {
"start": {
Expand Down Expand Up @@ -2114,7 +2114,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ô\u008f¿¿",
"value": null,
"raw": "'\\u{10ffff}'",
"loc": {
"start": {
Expand Down Expand Up @@ -2246,7 +2246,7 @@
"init": [
{
"type": "StringLiteral",
"value": "ð\u009f\u0092©",
"value": null,
"raw": "'\\u{000000001f4a9}'",
"loc": {
"start": {
Expand Down
12 changes: 6 additions & 6 deletions test/spec/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"init": [
{
"type": "StringLiteral",
"value": "foo",
"value": null,
"raw": "[[foo]]",
"loc": {
"start": {
Expand Down Expand Up @@ -669,7 +669,7 @@
"init": [
{
"type": "StringLiteral",
"value": "foo",
"value": null,
"raw": "\"foo\"",
"loc": {
"start": {
Expand Down Expand Up @@ -772,7 +772,7 @@
"init": [
{
"type": "StringLiteral",
"value": "foo",
"value": null,
"raw": "[[foo]]",
"loc": {
"start": {
Expand Down Expand Up @@ -1621,7 +1621,7 @@
},
"index": {
"type": "StringLiteral",
"value": "foo",
"value": null,
"raw": "\"foo\"",
"loc": {
"start": {
Expand Down Expand Up @@ -2780,7 +2780,7 @@
"type": "TableValue",
"value": {
"type": "StringLiteral",
"value": "-",
"value": null,
"raw": "'-'",
"loc": {
"start": {
Expand Down Expand Up @@ -2919,7 +2919,7 @@
"type": "TableValue",
"value": {
"type": "StringLiteral",
"value": "not",
"value": null,
"raw": "'not'",
"loc": {
"start": {
Expand Down
2 changes: 1 addition & 1 deletion test/spec/for.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@
"iterators": [
{
"type": "StringLiteral",
"value": "foo",
"value": null,
"raw": "\"foo\"",
"loc": {
"start": {
Expand Down
Loading

0 comments on commit be3c3ee

Please sign in to comment.