Best JavaScript code snippet using wpt
send-file-form-helper.js
Source:send-file-form-helper.js
1'use strict';2// See /FileAPI/file/resources/echo-content-escaped.py3function escapeString(string) {4 return string.replace(/\\/g, "\\\\").replace(5 /[^\x20-\x7E]/g,6 (x) => {7 let hex = x.charCodeAt(0).toString(16);8 if (hex.length < 2) hex = "0" + hex;9 return `\\x${hex}`;10 },11 ).replace(/\\x0d\\x0a/g, "\r\n");12}13// Rationale for this particular test character sequence, which is14// used in filenames and also in file contents:15//16// - ABC~ ensures the string starts with something we can read to17// ensure it is from the correct source; ~ is used because even18// some 1-byte otherwise-ASCII-like parts of ISO-2022-JP19// interpret it differently.20// - â¾Â¥ are inside a single-byte range of ISO-2022-JP and help21// diagnose problems due to filesystem encoding or locale22// - â is inside IBM437 and helps diagnose problems due to filesystem23// encoding or locale24// - ¤ is inside Latin-1 and helps diagnose problems due to25// filesystem encoding or locale; it is also the "simplest" case26// needing substitution in ISO-2022-JP27// - ï½¥ is inside a single-byte range of ISO-2022-JP in some variants28// and helps diagnose problems due to filesystem encoding or locale;29// on the web it is distinct when decoding but unified when encoding30// - ã» is inside a double-byte range of ISO-2022-JP and helps31// diagnose problems due to filesystem encoding or locale32// - ⢠is inside Windows-1252 and helps diagnose problems due to33// filesystem encoding or locale and also ensures these aren't34// accidentally turned into e.g. control codes35// - â is inside IBM437 and helps diagnose problems due to filesystem36// encoding or locale37// - · is inside Latin-1 and helps diagnose problems due to38// filesystem encoding or locale and also ensures HTML named39// character references (e.g. ·) are not used40// - â¼ is inside IBM437 shadowing C0 and helps diagnose problems due to41// filesystem encoding or locale and also ensures these aren't42// accidentally turned into e.g. control codes43// - â
is inside ISO-2022-JP on a non-Kanji page and makes correct44// output easier to spot45// - æ is inside ISO-2022-JP on a Kanji page and makes correct46// output easier to spot47// - ð is outside the BMP and makes incorrect surrogate pair48// substitution detectable and ensures substitutions work49// correctly immediately after Kanji 2-byte ISO-2022-JP50// - æ repeated here ensures the correct codec state is used51// after a non-BMP substitution52// - â
repeated here also makes correct output easier to spot53// - â¼ is inside IBM437 shadowing C0 and helps diagnose problems due to54// filesystem encoding or locale and also ensures these aren't55// accidentally turned into e.g. control codes and also ensures56// substitutions work correctly immediately after non-Kanji57// 2-byte ISO-2022-JP58// - · is inside Latin-1 and helps diagnose problems due to59// filesystem encoding or locale and also ensures HTML named60// character references (e.g. ·) are not used61// - â is inside IBM437 and helps diagnose problems due to filesystem62// encoding or locale63// - ⢠is inside Windows-1252 and again helps diagnose problems64// due to filesystem encoding or locale65// - ã» is inside a double-byte range of ISO-2022-JP and helps66// diagnose problems due to filesystem encoding or locale67// - ï½¥ is inside a single-byte range of ISO-2022-JP in some variants68// and helps diagnose problems due to filesystem encoding or locale;69// on the web it is distinct when decoding but unified when encoding70// - ¤ is inside Latin-1 and helps diagnose problems due to71// filesystem encoding or locale; again it is a "simple"72// substitution case73// - â is inside IBM437 and helps diagnose problems due to filesystem74// encoding or locale75// - ¥⾠are inside a single-byte range of ISO-2022-JP and help76// diagnose problems due to filesystem encoding or locale77// - ~XYZ ensures earlier errors don't lead to misencoding of78// simple ASCII79//80// Overall the near-symmetry makes common I18N mistakes like81// off-by-1-after-non-BMP easier to spot. All the characters82// are also allowed in Windows Unicode filenames.83const kTestChars = 'ABC~â¾Â¥â¤・ã»â¢â·â¼â
æðæâ
â¼Â·ââ¢ã»ï½¥Â¤âÂ¥â¾~XYZ';84// The kTestFallback* strings represent the expected byte sequence from85// encoding kTestChars with the given encoding with "html" replacement86// mode, isomorphic-decoded. That means, characters that can't be87// encoded in that encoding get HTML-escaped, but no further88// `escapeString`-like escapes are needed.89const kTestFallbackUtf8 = (90 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +91 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +92 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +93 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"94);95const kTestFallbackIso2022jp = (96 ("ABC~\x1B(J~\\â¤\x1B$B!&!&\x1B(Bâ¢â·â¼\x1B$B!z@1\x1B(Bð" +97 "\x1B$B@1!z\x1B(Bâ¼Â·ââ¢\x1B$B!&!&\x1B(B¤â\x1B(J\\~\x1B(B~XYZ")98 .replace(/[^\0-\x7F]/gu, (x) => `&#${x.codePointAt(0)};`)99);100const kTestFallbackWindows1252 = (101 "ABC~â¾\xA5â\xA4ï½¥ã»\x95â\xB7â¼â
æðæâ
â¼\xB7â\x95ã»ï½¥\xA4â\xA5â¾~XYZ".replace(102 /[^\0-\xFF]/gu,103 (x) => `&#${x.codePointAt(0)};`,104 )105);106const kTestFallbackXUserDefined = kTestChars.replace(107 /[^\0-\x7F]/gu,108 (x) => `&#${x.codePointAt(0)};`,109);110// formPostFileUploadTest - verifies multipart upload structure and111// numeric character reference replacement for filenames, field names,112// and field values using form submission.113//114// Uses /FileAPI/file/resources/echo-content-escaped.py to echo the115// upload POST with controls and non-ASCII bytes escaped. This is done116// because navigations whose response body contains [\0\b\v] may get117// treated as a download, which is not what we want. Use the118// `escapeString` function to replicate that kind of escape (note that119// it takes an isomorphic-decoded string, not a byte sequence).120//121// Fields in the parameter object:122//123// - fileNameSource: purely explanatory and gives a clue about which124// character encoding is the source for the non-7-bit-ASCII parts of125// the fileBaseName, or Unicode if no smaller-than-Unicode source126// contains all the characters. Used in the test name.127// - fileBaseName: the not-necessarily-just-7-bit-ASCII file basename128// used for the constructed test file. Used in the test name.129// - formEncoding: the acceptCharset of the form used to submit the130// test file. Used in the test name.131// - expectedEncodedBaseName: the expected formEncoding-encoded132// version of fileBaseName, isomorphic-decoded. That means, characters133// that can't be encoded in that encoding get HTML-escaped, but no134// further `escapeString`-like escapes are needed.135const formPostFileUploadTest = ({136 fileNameSource,137 fileBaseName,138 formEncoding,139 expectedEncodedBaseName,140}) => {141 promise_test(async testCase => {142 if (document.readyState !== 'complete') {143 await new Promise(resolve => addEventListener('load', resolve));144 }145 const formTargetFrame = Object.assign(document.createElement('iframe'), {146 name: 'formtargetframe',147 });148 document.body.append(formTargetFrame);149 testCase.add_cleanup(() => {150 document.body.removeChild(formTargetFrame);151 });152 const form = Object.assign(document.createElement('form'), {153 acceptCharset: formEncoding,154 action: '/FileAPI/file/resources/echo-content-escaped.py',155 method: 'POST',156 enctype: 'multipart/form-data',157 target: formTargetFrame.name,158 });159 document.body.append(form);160 testCase.add_cleanup(() => {161 document.body.removeChild(form);162 });163 // Used to verify that the browser agrees with the test about164 // which form charset is used.165 form.append(Object.assign(document.createElement('input'), {166 type: 'hidden',167 name: '_charset_',168 }));169 // Used to verify that the browser agrees with the test about170 // field value replacement and encoding independently of file system171 // idiosyncracies.172 form.append(Object.assign(document.createElement('input'), {173 type: 'hidden',174 name: 'filename',175 value: fileBaseName,176 }));177 // Same, but with name and value reversed to ensure field names178 // get the same treatment.179 form.append(Object.assign(document.createElement('input'), {180 type: 'hidden',181 name: fileBaseName,182 value: 'filename',183 }));184 const fileInput = Object.assign(document.createElement('input'), {185 type: 'file',186 name: 'file',187 });188 form.append(fileInput);189 // Removes c:\fakepath\ or other pseudofolder and returns just the190 // final component of filePath; allows both / and \ as segment191 // delimiters.192 const baseNameOfFilePath = filePath => filePath.split(/[\/\\]/).pop();193 await new Promise(resolve => {194 const dataTransfer = new DataTransfer;195 dataTransfer.items.add(196 new File([kTestChars], fileBaseName, {type: 'text/plain'}));197 fileInput.files = dataTransfer.files;198 // For historical reasons .value will be prefixed with199 // c:\fakepath\, but the basename should match the file name200 // exposed through the newer .files[0].name API. This check201 // verifies that assumption.202 assert_equals(203 baseNameOfFilePath(fileInput.files[0].name),204 baseNameOfFilePath(fileInput.value),205 `The basename of the field's value should match its files[0].name`);206 form.submit();207 formTargetFrame.onload = resolve;208 });209 const formDataText = formTargetFrame.contentDocument.body.textContent;210 const formDataLines = formDataText.split('\n');211 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {212 --formDataLines.length;213 }214 assert_greater_than(215 formDataLines.length,216 2,217 `${fileBaseName}: multipart form data must have at least 3 lines: ${218 JSON.stringify(formDataText)219 }`);220 const boundary = formDataLines[0];221 assert_equals(222 formDataLines[formDataLines.length - 1],223 boundary + '--',224 `${fileBaseName}: multipart form data must end with ${boundary}--: ${225 JSON.stringify(formDataText)226 }`);227 const asValue = expectedEncodedBaseName.replace(/\r\n?|\n/g, "\r\n");228 const asName = asValue.replace(/[\r\n"]/g, encodeURIComponent);229 const asFilename = expectedEncodedBaseName.replace(/[\r\n"]/g, encodeURIComponent);230 // The response body from echo-content-escaped.py has controls and non-ASCII231 // bytes escaped, so any caller-provided field that might contain such bytes232 // must be passed to `escapeString`, after any other expected233 // transformations.234 const expectedText = [235 boundary,236 'Content-Disposition: form-data; name="_charset_"',237 '',238 formEncoding,239 boundary,240 'Content-Disposition: form-data; name="filename"',241 '',242 // Unlike for names and filenames, multipart/form-data values don't escape243 // \r\n linebreaks, and when they're read from an iframe they become \n.244 escapeString(asValue).replace(/\r\n/g, "\n"),245 boundary,246 `Content-Disposition: form-data; name="${escapeString(asName)}"`,247 '',248 'filename',249 boundary,250 `Content-Disposition: form-data; name="file"; ` +251 `filename="${escapeString(asFilename)}"`,252 'Content-Type: text/plain',253 '',254 escapeString(kTestFallbackUtf8),255 boundary + '--',256 ].join('\n');257 assert_true(258 formDataText.startsWith(expectedText),259 `Unexpected multipart-shaped form data received:\n${260 formDataText261 }\nExpected:\n${expectedText}`);262 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...
aflprep_send-file-form-helper.js
Source:aflprep_send-file-form-helper.js
1'use strict';2function escapeString(string) {3 (x) => {4 let hex = x.charCodeAt(0).toString(16);5 if (hex.length < 2) hex = "0" + hex;6 return `\\x${hex}`;7 },8}9const kTestChars = 'ABC~â¾Â¥â¤・ã»â¢â·â¼â
æðæâ
â¼Â·ââ¢ã»ï½¥Â¤âÂ¥â¾~XYZ';10const kTestFallbackUtf8 = (11 "ABC~\xE2\x80\xBE\xC2\xA5\xE2\x89\x88\xC2\xA4\xEF\xBD\xA5\xE3\x83\xBB\xE2" +12 "\x80\xA2\xE2\x88\x99\xC2\xB7\xE2\x98\xBC\xE2\x98\x85\xE6\x98\x9F\xF0\x9F" +13 "\x8C\x9F\xE6\x98\x9F\xE2\x98\x85\xE2\x98\xBC\xC2\xB7\xE2\x88\x99\xE2\x80" +14 "\xA2\xE3\x83\xBB\xEF\xBD\xA5\xC2\xA4\xE2\x89\x88\xC2\xA5\xE2\x80\xBE~XYZ"15);16const kTestFallbackIso2022jp = (17 ("ABC~\x1B(J~\\â¤\x1B$B!&!&\x1B(Bâ¢â·â¼\x1B$B!z@1\x1B(Bð" +18 "\x1B$B@1!z\x1B(Bâ¼Â·ââ¢\x1B$B!&!&\x1B(B¤â\x1B(J\\~\x1B(B~XYZ")19);20const kTestFallbackWindows1252 = (21 "ABC~â¾\xA5â\xA4ï½¥ã»\x95â\xB7â¼â
æðæâ
â¼\xB7â\x95ã»ï½¥\xA4â\xA5â¾~XYZ".replace(22 (x) => `&#${x.codePointAt(0)};`,23 )24);25const kTestFallbackXUserDefined = kTestChars.replace(26 (x) => `&#${x.codePointAt(0)};`,27);28const formPostFileUploadTest = ({29 fileNameSource,30 fileBaseName,31 formEncoding,32 expectedEncodedBaseName,33}) => {34 promise_test(async testCase => {35 if (document.readyState !== 'complete') {36 await new Promise(resolve => addEventListener('load', resolve));37 }38 const formTargetFrame = Object.assign(document.createElement('iframe'), {39 name: 'formtargetframe',40 });41 document.body.append(formTargetFrame);42 testCase.add_cleanup(() => {43 document.body.removeChild(formTargetFrame);44 });45 const form = Object.assign(document.createElement('form'), {46 acceptCharset: formEncoding,47 method: 'POST',48 target: formTargetFrame.name,49 });50 document.body.append(form);51 testCase.add_cleanup(() => {52 document.body.removeChild(form);53 });54 form.append(Object.assign(document.createElement('input'), {55 type: 'hidden',56 name: '_charset_',57 }));58 form.append(Object.assign(document.createElement('input'), {59 type: 'hidden',60 name: 'filename',61 value: fileBaseName,62 }));63 form.append(Object.assign(document.createElement('input'), {64 type: 'hidden',65 name: fileBaseName,66 value: 'filename',67 }));68 const fileInput = Object.assign(document.createElement('input'), {69 type: 'file',70 name: 'file',71 });72 form.append(fileInput);73 await new Promise(resolve => {74 const dataTransfer = new DataTransfer;75 dataTransfer.items.add(76 fileInput.files = dataTransfer.files;77 assert_equals(78 baseNameOfFilePath(fileInput.files[0].name),79 baseNameOfFilePath(fileInput.value),80 `The basename of the field's value should match its files[0].name`);81 form.submit();82 formTargetFrame.onload = resolve;83 });84 const formDataText = formTargetFrame.contentDocument.body.textContent;85 const formDataLines = formDataText.split('\n');86 if (formDataLines.length && !formDataLines[formDataLines.length - 1]) {87 --formDataLines.length;88 }89 assert_greater_than(90 formDataLines.length,91 2,92 `${fileBaseName}: multipart form data must have at least 3 lines: ${93 JSON.stringify(formDataText)94 }`);95 const boundary = formDataLines[0];96 assert_equals(97 formDataLines[formDataLines.length - 1],98 boundary + '--',99 `${fileBaseName}: multipart form data must end with ${boundary}--: ${100 JSON.stringify(formDataText)101 }`);102 const expectedText = [103 boundary,104 'Content-Disposition: form-data; name="_charset_"',105 '',106 formEncoding,107 boundary,108 'Content-Disposition: form-data; name="filename"',109 '',110 boundary,111 `Content-Disposition: form-data; name="${escapeString(asName)}"`,112 '',113 'filename',114 boundary,115 `Content-Disposition: form-data; name="file"; ` +116 `filename="${escapeString(asFilename)}"`,117 '',118 escapeString(kTestFallbackUtf8),119 boundary + '--',120 ].join('\n');121 assert_true(122 formDataText.startsWith(expectedText),123 `Unexpected multipart-shaped form data received:\n${124 formDataText125 }\nExpected:\n${expectedText}`);126 }, `Upload ${fileBaseName} (${fileNameSource}) in ${formEncoding} form`);...
Using AI Code Generation
1add_filter( 'pre_option_use_smilies', '__return_true' );2add_filter( 'pre_option_use_balanceTags', '__return_true' );3add_filter( 'pre_option_use_smilies', '__return_true' );4add_filter( 'pre_option_use_balanceTags', '__return_true' );5add_filter( 'pre_option_use_smilies', '__return_true' );6add_filter( 'pre_option_use_balanceTags', '__return_true' );7add_filter( 'pre_option_use_smilies', '__return_true' );8add_filter( 'pre_option_use_balanceTags', '__return_true' );9add_filter( 'pre_option_use_smilies', '__return_true' );10add_filter( 'pre_option_use_balanceTags', '__return_true' );11add_filter( 'pre_option_use_smilies', '__return_true' );12add_filter( 'pre_option_use_balanceTags', '__return_true' );13add_filter( 'pre_option_use_smilies', '__return_true' );14add_filter( 'pre_option_use_balanceTags', '__return_true' );15add_filter( 'pre_option_use_smilies', '__return_true' );16add_filter( 'pre_option_use_balanceTags', '__return_true' );17add_filter( 'pre_option_use_smilies', '__return_true' );18add_filter( 'pre_option_use_balanceTags', '__return_true' );19add_filter( 'pre_option_use_smilies', '__return_true' );20add_filter( 'pre_option_use_balanceTags', '__return_true' );21add_filter( 'pre_option_use_smilies', '__return_true' );22add_filter( 'pre_option_use_balanceTags', '__return_true' );23add_filter( 'pre_option_use_smilies', '__return_true' );24add_filter( 'pre_option_use_balanceTags', '__return_true' );25add_filter( 'pre_option_use_smilies', '__return_true' );26add_filter( 'pre_option_use_balanceTags', '__return_true' );27add_filter( 'pre_option_use_smilies', '__return_true' );28add_filter( 'pre_option_use_balanceTags', '__return_true' );29add_filter( 'pre_option_use_smilies', '__return_true' );30add_filter( 'pre_option_use_balanceTags', '__return_true' );31add_filter( 'pre_option_use_smilies', '__return_true' );32add_filter( 'pre_option_use_balanceTags', '__return_true' );33add_filter( 'pre_option_use_smilies', '__return_true' );
Using AI Code Generation
1var decoder = new TextDecoder('iso-2022-jp', {fatal: false});2var input = new Uint8Array([0x1b, 0x24, 0x42, 0x21, 0x21, 0x1b, 0x28, 0x42]);3var output = decoder.decode(input);4var decoder = new TextDecoder('iso-2022-jp', {fatal: true});5var input = new Uint8Array([0x1b, 0x24, 0x42, 0x21, 0x21, 0x1b, 0x28, 0x42]);6var output = decoder.decode(input);7var decoder = new TextDecoder('iso-2022-jp', {fatal: true});8var input = new Uint8Array([0x1b, 0x24, 0x42, 0x21, 0x21, 0x1b, 0x28, 0x42]);9var output = decoder.decode(input);10var decoder = new TextDecoder('iso-2022-jp', {fatal: false});11var input = new Uint8Array([0x1b, 0x24, 0x42, 0x21, 0x21, 0x1b, 0x28, 0x42]);12var output = decoder.decode(input);13var decoder = new TextDecoder('iso-2022-jp', {fatal: false});14var input = new Uint8Array([0x1b, 0x24, 0x42, 0x21, 0x21, 0x1b, 0x28, 0x42]);15var output = decoder.decode(input);
Using AI Code Generation
1var encoder = new TextEncoder("iso-2022-jp");2var decoder = new TextDecoder("iso-2022-jp");3var encoded = encoder.encode("test");4var decoded = decoder.decode(encoded);5console.log(decoded);6var kTestFallbackIso2022jp = {7 encode: function(str) {8 return [0x1b, 0x24, 0x42, 0x74, 0x65, 0x73, 0x74, 0x1b, 0x28, 0x42];9 },10 decode: function(bytes) {11 return "test";12 }13};14var encoder = new TextEncoder("iso-2022-jp");15var decoder = new TextDecoder("iso-2022-jp");16var encoded = encoder.encode("test");17var decoded = decoder.decode(encoded);18console.log(decoded);19var kTestFallbackIso2022jp = {
Using AI Code Generation
1function test_wptexturize( $text ) {2 $text = str_replace( 'test', 'test2', $text );3 return $text;4}5function wptexturize( $text ) {6 global $wptexturize;7 if ( in_array( $text, $wptexturize->done, true ) ) {8 return $text;9 }10 $original_text = $text;11 if ( false !== strpos( $text, '&' ) ) {12 $textarr = preg_split( '/(&#?[a-z0-9]{2,8};)/i', $text, -1, PREG_SPLIT_DELIM_CAPTURE );13 $stop = count( $textarr );14 for ( $i = 0; $i < $stop; $i++ ) {15 if ( $i % 2 == 0 ) {16 $textarr[ $i ] = $wptexturize->texturize( $textarr[ $i ] );17 } else {18 $textarr[ $i ] = $wptexturize->no_texturize( $textarr[ $i ] );19 }20 }21 $text = implode( '', $textarr );22 } else {23 $text = $wptexturize->texturize( $text );24 }25 $wptexturize->done[] = $original_text;26 return $text;27}28public function texturize( $text ) {29 $textarr = preg_split( '/(<.*>)/Us', $text, -1, PREG_SPLIT_DELIM_CAPTURE );30 $stop = count( $textarr );31 $tags_to_ignore = 'code|pre|style|script|textarea';
Using AI Code Generation
1var kTestFallbackIso2022jp = 0x00000001;2var kTestFallbackIso2022jp = 0x00000002;3var decoder = new TextDecoder("iso-2022-jp", {fatal: false, ignoreBOM: false, stream: false, flags: kTestFallbackIso2022jp});4var encodedText = "abc";5var decodedText = decoder.decode(encodedText);6console.log(decodedText);7var encodedText = "abc";8var decodedText = decoder.decode(encodedText, {stream: true});9console.log(decodedText);10var encodedText = "abc";11var decodedText = decoder.decode(encodedText, {stream: true});12console.log(decodedText);13var encodedText = "abc";14var decodedText = decoder.decode(encodedText);15console.log(decodedText);16var encodedText = "abc";17var decodedText = decoder.decode(encodedText, {stream: true});18console.log(decodedText);19var encodedText = "abc";20var decodedText = decoder.decode(encodedText, {stream: true});21console.log(decodedText);22var encodedText = "abc";23var decodedText = decoder.decode(encodedText);24console.log(decodedText);25var encodedText = "abc";26var decodedText = decoder.decode(encodedText, {stream: true});27console.log(decodedText);28var encodedText = "abc";29var decodedText = decoder.decode(encodedText, {stream: true});30console.log(decodedText);31var encodedText = "abc";32var decodedText = decoder.decode(encodedText);33console.log(decodedText);34var encodedText = "abc";35var decodedText = decoder.decode(encodedText, {stream: true});36console.log(decodedText);37var encodedText = "abc";38var decodedText = decoder.decode(encodedText, {stream: true});39console.log(decodedText);40var encodedText = "abc";41var decodedText = decoder.decode(encodedText);42console.log(decodedText);43var encodedText = "abc";44var decodedText = decoder.decode(encodedText, {stream: true});
Using AI Code Generation
1var kTestFallbackIso2022jp = 0x40;2var kTestFallbackUtf8 = 0x80;3var kTestFallbackError = 0x100;4var kTestFallbackMask = 0x1c0;5function testFallbackMethod(aString, aMethod) {6 var str = wptexturize(aString, aMethod);7 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);8 conv.charset = "ISO-2022-JP";9 var str2 = conv.ConvertToUnicode(str);10 conv.charset = "UTF-8";11 str2 = conv.ConvertToUnicode(str2);12 return str2;13}14var str = "Hello, world! こんにちは!";15var str2 = testFallbackMethod(str, kTestFallbackIso2022jp);16dump(str2 + "17");18var kTestFallbackIso2022jp = 0x40;19var kTestFallbackUtf8 = 0x80;20var kTestFallbackError = 0x100;21var kTestFallbackMask = 0x1c0;22function testFallbackMethod(aString, aMethod) {23 var str = wptexturize(aString, aMethod);24 .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);25 conv.charset = "ISO-2022-JP";26 var str2 = conv.ConvertToUnicode(str);27 conv.charset = "UTF-8";28 str2 = conv.ConvertToUnicode(str2);29 return str2;30}31var str = "Hello, world! こんにちは!";32var str2 = testFallbackMethod(str, kTestFallbackUtf8);33dump(str2 + "34");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!