v2
3/13/2023 by benjie -00
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
function escapeIdentifierLoop(str) {
  var escaped = '"'

  for (var i = 0; i < str.length; i++) {
    var c = str[i]
    if (c === '"') {
      escaped += c + c
    } else if (c === '\0') {
      throw new Error("\\0 forbidden");
    } else {
      escaped += c
    }
  }

  escaped += '"'

  return escaped
}

function escapeIdentifierRegexpAndError(str) {
  if (/\0/.test(str)) throw new Error("\\0 forbidden");
  return '"' + str.replace(/"/g, '""') + '"'
}

function escapeIdentifierRegexpAndInvisibleSub(str) {
  return '"' + str.replace(/["\0]/g, '""') + '"'
}

function escapeIdentifierUnsafe(str) {
  return '"' + str.replace(/"/g, '""') + '"'
}


const strings = [];
const escaped = [];

for (let i = 0; i < 100_000; i++) {
	strings.push(String(i) + "some_identifier" + String(i));
}
delete caserun single casemove downdrag and drop case


ready



for (let i = 0, l = strings.length; i < l; i++) {
	escaped[i] = escapeIdentifierRegexpAndInvisibleSub(strings[i]);
}
delete caserun single casemove upmove downdrag and drop case


ready



for (let i = 0, l = strings.length; i < l; i++) {
	escaped[i] = escapeIdentifierRegexpAndError(strings[i]);
}
delete caserun single casemove upmove downdrag and drop case


ready



for (let i = 0, l = strings.length; i < l; i++) {
	escaped[i] = escapeIdentifierLoop(strings[i]);
}
delete caserun single casemove updrag and drop case


ready



for (let i = 0, l = strings.length; i < l; i++) {
	escaped[i] = escapeIdentifierUnsafe(strings[i]);
}
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN