11'use strict'
22
33var util = require ( 'util' )
4-
5- var shellQuote = function ( value ) {
6- // Unless `value` is a simple shell-safe string, quote it.
7- var shellSafe = / ^ [ a - z 0 - 9 - _ / .@ % ^ = : ] + $ / i
8- if ( ! shellSafe . test ( value ) ) {
9- // Use "strong quoting" using single quotes so that we only need
10- // to deal with nested single quote characters.
11- // <http://wiki.bash-hackers.org/syntax/quoting#strong_quoting>
12- return util . format ( "'%s'" , value . replace ( / ' / g, "'\\''" ) )
13- }
14- return value
15- }
4+ var quote = require ( '../helpers/shell/quote' )
165
176module . exports = function ( source , options ) {
187 var opts = util . _extend ( {
@@ -34,7 +23,7 @@ module.exports = function (source, options) {
3423
3524 // start with body pipe
3625 if ( source . postData && source . postData . text ) {
37- code . push ( util . format ( 'echo %s | ' , shellQuote ( source . postData . text ) ) )
26+ code . push ( util . format ( 'echo %s | ' , quote ( source . postData . text ) ) )
3827 }
3928
4029 var flags = [ ]
@@ -75,7 +64,7 @@ module.exports = function (source, options) {
7564 flags . push ( util . format ( '--timeout=%s' , opts . timeout ) )
7665 }
7766
78- code . push ( util . format ( 'http %s%s %s' , flags . length ? flags . join ( ' ' ) + ' ' : '' , source . method , shellQuote ( opts . queryParams ? source . url : source . fullUrl ) ) )
67+ code . push ( util . format ( 'http %s%s %s' , flags . length ? flags . join ( ' ' ) + ' ' : '' , source . method , quote ( opts . queryParams ? source . url : source . fullUrl ) ) )
7968
8069 // construct query params
8170 if ( opts . queryParams ) {
@@ -86,23 +75,23 @@ module.exports = function (source, options) {
8675
8776 if ( util . isArray ( value ) ) {
8877 value . map ( function ( val ) {
89- code . push ( util . format ( '%s==%s' , name , shellQuote ( val ) ) )
78+ code . push ( util . format ( '%s==%s' , name , quote ( val ) ) )
9079 } )
9180 } else {
92- code . push ( util . format ( '%s==%s' , name , shellQuote ( value ) ) )
81+ code . push ( util . format ( '%s==%s' , name , quote ( value ) ) )
9382 }
9483 } )
9584 }
9685
9786 // construct headers
9887 Object . keys ( source . allHeaders ) . sort ( ) . map ( function ( key ) {
99- code . push ( util . format ( '%s:%s' , key , shellQuote ( source . allHeaders [ key ] ) ) )
88+ code . push ( util . format ( '%s:%s' , key , quote ( source . allHeaders [ key ] ) ) )
10089 } )
10190
10291 // construct post params
10392 if ( ! source . postData . text && source . postData . params && source . postData . params . length ) {
10493 source . postData . params . map ( function ( param ) {
105- code . push ( util . format ( '%s:%s' , param . name , shellQuote ( param . value ) ) )
94+ code . push ( util . format ( '%s:%s' , param . name , quote ( param . value ) ) )
10695 } )
10796 }
10897
0 commit comments