basant307/AI_Governance_Project
048
1'use strict';2 3/** @import { ControlOperator } from './parse' */4 5/** @type {ControlOperator['op'][]} */6var OPS = /** @type {const} */ ([7 '||',8 '&&',9 ';;',10 '|&',11 '<(',12 '<<<',13 '>>',14 '>&',15 '<&',16 '&',17 ';',18 '(',19 ')',20 '|',21 '<',22 '>'23]);24var LINE_TERMINATORS = /[\n\r\u2028\u2029]/;25var GLOB_SHELL_SPECIAL = /[\s#!"$&'():;<=>@\\^`|]/g;26 27/** @type {import('./quote')} */28module.exports = function quote(xs) {29 return xs.map(function (s) {30 if (s === '') {31 return /** @type {const} */ ('\'\'');32 }33 if (s && typeof s === 'object') {34 if ('op' in s && s.op === 'glob') {35 if (typeof s.pattern !== 'string') {36 throw new TypeError('glob token requires a string `pattern`');37 }38 if (LINE_TERMINATORS.test(s.pattern)) {39 throw new TypeError('glob `pattern` must not contain line terminators');40 }41 return s.pattern.replace(GLOB_SHELL_SPECIAL, '\\$&');42 }43 if ('op' in s && typeof s.op === 'string') {44 if (OPS.indexOf(s.op) < 0) {45 throw new TypeError('invalid `op` value: ' + JSON.stringify(s.op));46 }47 return s.op.replace(/[\s\S]/g, '\\$&');48 }49 if ('comment' in s && typeof s.comment === 'string') {50 if (LINE_TERMINATORS.test(s.comment)) {51 throw new TypeError('`comment` must not contain line terminators');52 }53 return '#' + s.comment;54 }55 throw new TypeError('unrecognized object token shape');56 }57 if ((/["\s\\]/).test(s) && !(/'/).test(s)) {58 return "'" + s.replace(/(['])/g, '\\$1') + "'";59 }60 if ((/["'\s]/).test(s)) {61 return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';62 }63 return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}~])/g, '$1\\$2');64 }).join(' ');65};66 