"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/escape-exec-path.js" (8 Mar 2017, 777 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 'use strict'
    2 var path = require('path')
    3 var isWindowsShell = require('./is-windows-shell.js')
    4 
    5 /*
    6 Escape the name of an executable suitable for passing to the system shell.
    7 
    8 Windows is easy, wrap in double quotes and you're done, as there's no
    9 facility to create files with quotes in their names.
   10 
   11 Unix-likes are a little more complicated, wrap in single quotes and escape
   12 any single quotes in the filename.
   13 */
   14 
   15 module.exports = escapify
   16 
   17 function windowsQuotes (str) {
   18   if (!/ /.test(str)) return str
   19   return '"' + str + '"'
   20 }
   21 
   22 function escapify (str) {
   23   if (isWindowsShell) {
   24     return path.normalize(str).split(/\\/).map(windowsQuotes).join('\\')
   25   } else if (/[^-_.~/\w]/.test(str)) {
   26     return "'" + str.replace(/'/g, "'\"'\"'") + "'"
   27   } else {
   28     return str
   29   }
   30 }