guardia-messenger/node_modules/shell-quote/test/quote.js
DESKTOP-TKLFCPRython f29f525c77 refactor: 101.79.17.164 → zioinfo.co.kr 전체 도메인 변환 + Manager UI 배포
- 37개 파일 IP → zioinfo.co.kr 치환 (소스/매뉴얼/설정/하네스)
- Manager DrConsole/NetworkConsole/CsapConsole 빌드 + /var/www/manager/ 배포
- 테스트: Manager HTTP 200, ITSM 신규 API 7개 전체 200

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 10:09:17 +09:00

117 lines
4.3 KiB
JavaScript

'use strict';
var test = require('tape');
var quote = require('../').quote;
test('quote', function (t) {
t.equal(quote(['a', 'b', 'c d']), 'a b \'c d\'');
t.equal(
quote(['a', 'b', "it's a \"neat thing\""]),
'a b "it\'s a \\"neat thing\\""'
);
t.equal(
quote(['$', '`', '\'']),
'\\$ \\` "\'"'
);
t.equal(quote([]), '');
t.equal(quote(['a\nb']), "'a\nb'");
t.equal(quote([' #(){}*|][!']), "' #(){}*|][!'");
t.equal(quote(["'#(){}*|][!"]), '"\'#(){}*|][\\!"');
t.equal(quote(['X#(){}*|][!']), 'X\\#\\(\\)\\{\\}\\*\\|\\]\\[\\!');
t.equal(quote(['a\n#\nb']), "'a\n#\nb'");
t.equal(quote(['><;{}']), '\\>\\<\\;\\{\\}');
t.equal(quote(['a', 1, true, false]), 'a 1 true false');
t.equal(quote(['a', 1, null, undefined]), 'a 1 null undefined');
t.equal(quote(['a\\x']), "'a\\x'");
t.equal(quote(['a"b']), '\'a"b\'');
t.equal(quote(['"a"b"']), '\'"a"b"\'');
t.equal(quote(['a\\"b']), '\'a\\"b\'');
t.equal(quote(['a\\b']), '\'a\\b\'');
t.end();
});
test('quote ops', function (t) {
t.equal(quote(['a', { op: '|' }, 'b']), 'a \\| b');
t.equal(
quote(['a', { op: '&&' }, 'b', { op: ';' }, 'c']),
'a \\&\\& b \\; c'
);
t.end();
});
test('quote windows paths', { skip: 'breaking change, disabled until 2.x' }, function (t) {
var path = 'C:\\projects\\node-shell-quote\\index.js';
t.equal(quote([path, 'b', 'c d']), 'C:\\projects\\node-shell-quote\\index.js b \'c d\'');
t.end();
});
test("chars for windows paths don't break out", function (t) {
var x = '`:\\a\\b';
t.equal(quote([x]), "'`:\\a\\b'");
t.end();
});
test('empty strings', function (t) {
t.equal(quote(['-x', '', 'y']), '-x \'\' y');
t.end();
});
test('quote ops: allowlist', function (t) {
var ops = ['||', '&&', ';;', '|&', '<(', '<<<', '>>', '>&', '<&', '&', ';', '(', ')', '|', '<', '>'];
for (var i = 0; i < ops.length; i++) {
var op = ops[i];
var expected = '';
for (var j = 0; j < op.length; j++) { expected += '\\' + op.charAt(j); }
t.equal(quote([{ op: op }]), expected, 'op ' + op);
}
t.end();
});
test('quote ops: rejects line terminators (GHSA-w7jw-789q-3m8p)', function (t) {
t['throws'](function () { quote([{ op: ';\nid' }]); }, TypeError, 'newline in op');
t['throws'](function () { quote([{ op: ';\rid' }]); }, TypeError, 'carriage return in op');
t['throws'](function () { quote([{ op: ';\u2028id' }]); }, TypeError, 'U+2028 in op');
t['throws'](function () { quote([{ op: ';\u2029id' }]); }, TypeError, 'U+2029 in op');
t.end();
});
test('quote ops: rejects non-allowlisted values', function (t) {
t['throws'](function () { quote([{ op: '' }]); }, TypeError, 'empty op');
t['throws'](function () { quote([{ op: 'foo' }]); }, TypeError, 'arbitrary string');
t['throws'](function () { quote([{ op: '|||' }]); }, TypeError, 'near-miss');
t['throws'](function () { quote([{ op: 42 }]); }, TypeError, 'non-string op');
t.end();
});
test('quote glob pattern', function (t) {
t.equal(quote([{ op: 'glob', pattern: 'test/*.test.js' }]), 'test/*.test.js');
t.equal(quote([{ op: 'glob', pattern: '?ab' }]), '?ab');
t.equal(quote([{ op: 'glob', pattern: '[ab]c' }]), '[ab]c');
t.equal(quote([{ op: 'glob', pattern: '{a,b}' }]), '{a,b}');
t.equal(quote([{ op: 'glob', pattern: 'my dir/*.txt' }]), 'my\\ dir/*.txt');
t.equal(quote([{ op: 'glob', pattern: 'a$b' }]), 'a\\$b');
t['throws'](function () { quote([{ op: 'glob' }]); }, TypeError, 'missing pattern');
t['throws'](function () { quote([{ op: 'glob', pattern: 'a\nb' }]); }, TypeError, 'newline in pattern');
t['throws'](function () { quote([{ op: 'glob', pattern: 'a\u2028b' }]); }, TypeError, 'U+2028 in pattern');
t.end();
});
test('quote comment', function (t) {
t.equal(quote(['echo', 'hi', { comment: ' a comment' }]), 'echo hi # a comment');
t.equal(quote([{ comment: '' }]), '#');
t['throws'](function () { quote([{ comment: 'a\nb' }]); }, TypeError, 'newline in comment');
t['throws'](function () { quote([{ comment: 'a\rb' }]); }, TypeError, 'CR in comment');
t['throws'](function () { quote([{ comment: 'a\u2028b' }]); }, TypeError, 'U+2028 in comment');
t.end();
});
test('quote rejects unrecognized object shapes', function (t) {
t['throws'](function () { quote([{}]); }, TypeError, 'empty object');
t['throws'](function () { quote([{ foo: 'bar' }]); }, TypeError, 'unknown key');
t['throws'](function () { quote([{ op: null }]); }, TypeError, 'null op');
t.end();
});