How to use rfc2231getparam method in wpt

Best JavaScript code snippet using wpt

content_disposition.js

Source:content_disposition.js Github

copy

Full Screen

...13 filename = rfc5987decode(filename);14 filename = rfc2047decode(filename);15 return fixupEncoding(filename);16 }17 tmp = rfc2231getparam(contentDisposition);18 if (tmp) {19 let filename = rfc2047decode(tmp);20 return fixupEncoding(filename);21 }22 tmp = toParamRegExp('filename', 'i').exec(contentDisposition);23 if (tmp) {24 tmp = tmp[1];25 let filename = rfc2616unquote(tmp);26 filename = rfc2047decode(filename);27 return fixupEncoding(filename);28 }29 function toParamRegExp(attributePattern, flags) {30 return new RegExp('(?:^|;)\\s*' + attributePattern + '\\s*=\\s*' + '(' + '[^";\\s][^;\\s]*' + '|' + '"(?:[^"\\\\]|\\\\"?)+"?' + ')', flags);31 }32 function textdecode(encoding, value) {33 if (encoding) {34 if (!/^[\x00-\xFF]+$/.test(value)) {35 return value;36 }37 try {38 let decoder = new TextDecoder(encoding, {39 fatal: true40 });41 let bytes = Array.from(value, function (ch) {42 return ch.charCodeAt(0) & 0xFF;43 });44 value = decoder.decode(new Uint8Array(bytes));45 needsEncodingFixup = false;46 } catch (e) {47 if (/^utf-?8$/i.test(encoding)) {48 try {49 value = decodeURIComponent(escape(value));50 needsEncodingFixup = false;51 } catch (err) {}52 }53 }54 }55 return value;56 }57 function fixupEncoding(value) {58 if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {59 value = textdecode('utf-8', value);60 if (needsEncodingFixup) {61 value = textdecode('iso-8859-1', value);62 }63 }64 return value;65 }66 function rfc2231getparam(contentDisposition) {67 let matches = [],68 match;69 let iter = toParamRegExp('filename\\*((?!0\\d)\\d+)(\\*?)', 'ig');70 while ((match = iter.exec(contentDisposition)) !== null) {71 let [, n, quot, part] = match;72 n = parseInt(n, 10);73 if (n in matches) {74 if (n === 0) {75 break;76 }77 continue;78 }79 matches[n] = [quot, part];80 }...

Full Screen

Full Screen

content_disposition.ts

Source:content_disposition.ts Github

copy

Full Screen

1/**2 * Adapted directly from content-disposition.js at3 * https://github.com/Rob--W/open-in-browser/blob/master/extension/content-disposition.js4 * which is licensed as:5 *6 * (c) 2017 Rob Wu <rob@robwu.nl> (https://robwu.nl)7 * This Source Code Form is subject to the terms of the Mozilla Public8 * License, v. 2.0. If a copy of the MPL was not distributed with this9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.10 */11import {toParamRegExp, unquote} from "./headers.ts";12let needsEncodingFixup = false;13function fixupEncoding(value: string): string {14 if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {15 value = textDecode("utf-8", value);16 if (needsEncodingFixup) {17 value = textDecode("iso-8859-1", value);18 }19 }20 return value;21}22const FILENAME_STAR_REGEX = toParamRegExp("filename\\*", "i");23const FILENAME_START_ITER_REGEX = toParamRegExp(24 "filename\\*((?!0\\d)\\d+)(\\*?)",25 "ig"26);27const FILENAME_REGEX = toParamRegExp("filename", "i");28function rfc2047decode(value: string): string {29 // deno-lint-ignore no-control-regex30 if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {31 return value;32 }33 return value.replace(34 /=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,35 (_: string, charset: string, encoding: string, text: string) => {36 if (encoding === "q" || encoding === "Q") {37 text = text.replace(/_/g, " ");38 text = text.replace(/=([0-9a-fA-F]{2})/g, (_, hex) =>39 String.fromCharCode(parseInt(hex, 16))40 );41 return textDecode(charset, text);42 }43 try {44 text = atob(text);45 // deno-lint-ignore no-empty46 } catch {}47 return textDecode(charset, text);48 }49 );50}51function rfc2231getParam(header: string): string {52 const matches: [string, string][] = [];53 let match: RegExpExecArray | null;54 while ((match = FILENAME_START_ITER_REGEX.exec(header))) {55 const [, ns, quote, part] = match;56 const n = parseInt(ns, 10);57 if (n in matches) {58 if (n === 0) {59 break;60 }61 continue;62 }63 matches[n] = [quote, part];64 }65 const parts: string[] = [];66 for (let n = 0; n < matches.length; ++n) {67 if (!(n in matches)) {68 break;69 }70 let [quote, part] = matches[n];71 part = unquote(part);72 if (quote) {73 part = unescape(part);74 if (n === 0) {75 part = rfc5987decode(part);76 }77 }78 parts.push(part);79 }80 return parts.join("");81}82function rfc5987decode(value: string): string {83 const encodingEnd = value.indexOf(`'`);84 if (encodingEnd === -1) {85 return value;86 }87 const encoding = value.slice(0, encodingEnd);88 const langValue = value.slice(encodingEnd + 1);89 return textDecode(encoding, langValue.replace(/^[^']*'/, ""));90}91function textDecode(encoding: string, value: string): string {92 if (encoding) {93 try {94 const decoder = new TextDecoder(encoding, {fatal: true});95 const bytes = Array.from(value, (c) => c.charCodeAt(0));96 if (bytes.every((code) => code <= 0xff)) {97 value = decoder.decode(new Uint8Array(bytes));98 needsEncodingFixup = false;99 }100 // deno-lint-ignore no-empty101 } catch {}102 }103 return value;104}105export function getFilename(header: string): string {106 needsEncodingFixup = true;107 // filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).108 let matches = FILENAME_STAR_REGEX.exec(header);109 if (matches) {110 const [, filename] = matches;111 return fixupEncoding(112 rfc2047decode(rfc5987decode(unescape(unquote(filename))))113 );114 }115 // Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).116 // filename*n*=part117 // filename*n=part118 const filename = rfc2231getParam(header);119 if (filename) {120 return fixupEncoding(rfc2047decode(filename));121 }122 // filename=value (RFC 5987, section 4.1).123 matches = FILENAME_REGEX.exec(header);124 if (matches) {125 const [, filename] = matches;126 return fixupEncoding(rfc2047decode(unquote(filename)));127 }128 return "";...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var rfc2231getparam = require('wptools').rfc2231getparam;2var str = "filename*=UTF-8''%e4%bd%a0%e5%a5%bd.txt";3console.log(rfc2231getparam(str));4var rfc2231parse = require('wptools').rfc2231parse;5var str = "filename*=UTF-8''%e4%bd%a0%e5%a5%bd.txt";6console.log(rfc2231parse(str));7var rfc2231build = require('wptools').rfc2231build;8var str = "filename*=UTF-8''%e4%bd%a0%e5%a5%bd.txt";9console.log(rfc2231build(str));10var rfc5987getparam = require('wptools').rfc5987getparam;11var str = "filename*=UTF-8''%e4%bd%a0%e5%a5%bd.txt";12console.log(rfc5987getparam(str));13var rfc5987parse = require('wptools').rfc5987parse;14var str = "filename*=UTF-8''%e4%bd%a0%e5%a5%bd.txt";15console.log(rfc5987parse(str));16var rfc5987build = require('wptools').rfc5987build;

Full Screen

Using AI Code Generation

copy

Full Screen

1var rfc2231getparam = require('./rfc2231getparam.js').rfc2231getparam;2var url = process.argv[2];3rfc2231getparam(url, function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var request = require('request');11var cheerio = require('cheerio');12var iconv = require('iconv-lite');13var rfc2231getparam = function(url, callback) {14 var options = {15 };16 request(options, function(err, res, body) {17 if(err) {18 callback(err);19 } else {20 var $ = cheerio.load(iconv.decode(body, 'ISO-8859-1'));21 var param = $('param[name="rfc2231"]').attr('value');22 callback(null, param);23 }24 });25};26module.exports.rfc2231getparam = rfc2231getparam;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var params = wptools.rfc2231getparam(url);4console.log(params);5var wptools = require('wptools');6var fs = require('fs');7var params = wptools.rfc2231getparam(url);8console.log(params);9var wptools = require('wptools');10var fs = require('fs');11var params = wptools.rfc2231getparam(url);12console.log(params);13var wptools = require('wptools');14var fs = require('fs');15var params = wptools.rfc2231getparam(url);16console.log(params);17var wptools = require('wptools');18var fs = require('fs');19var params = wptools.rfc2231getparam(url);20console.log(params);21var wptools = require('wptools');22var fs = require('fs');23var params = wptools.rfc2231getparam(url);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var options = {3 headers: {4 'content-disposition': 'attachment; filename*=UTF-8''%E2%82%AC%20rates'5 }6};7var request = wptools.request(url, options, function (err, response) {8 console.log(response.headers['content-disposition']);9 console.log(wptools.rfc2231getparam(response.headers['content-disposition'], 'filename'));10});11request.end();12attachment; filename*=UTF-8''%E2%82%AC%20rates

Full Screen

Using AI Code Generation

copy

Full Screen

1function test()2{3 var testname = "RFC2231getparam";4 var testpath = "test.js";5 var testdesc = "RFC2231getparam method of wpt";6 var testfile = "testfile.txt";

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful