wp-advads 1.0.38 → 1.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "wp-advads",
4
- "version": "1.0.38",
4
+ "version": "1.0.39",
5
5
  "description": "Create an Advanced Ads WordPress plugin ecosystem.",
6
6
  "author": {
7
7
  "name": "Shakeeb Ahmed",
@@ -3,46 +3,12 @@
3
3
  */
4
4
  import { spawn } from 'node:child_process'
5
5
 
6
- // cmd.exe metacharacters. See https://github.com/moxystudio/node-cross-spawn/blob/v7.0.6/lib/util/escape.js
7
- const WIN_META = /([()\][%!^"`<>&|;, *?])/g
8
-
9
- function escapeWinCommand( arg ) {
10
- return String( arg ).replace( WIN_META, '^$1' )
11
- }
12
-
13
- function escapeWinArgument( arg ) {
14
- let value = String( arg )
15
- value = value.replace( /(?=(\\+?)?)\1"/g, '$1$1\\"' )
16
- value = value.replace( /(?=(\\+?)?)\1$/, '$1$1' )
17
- value = `"${value}"`
18
- return value.replace( WIN_META, '^$1' )
19
- }
20
-
21
- /**
22
- * Windows argv spawn must go through cmd.exe so PATHEXT (.cmd/.bat) resolves.
23
- * Direct spawn('wp') looks for wp.exe only and throws ENOENT.
24
- *
25
- * @param {string} file Command name
26
- * @param {string[]} args Arguments
27
- * @param {string} [comspec] cmd.exe path
28
- * @returns {{ file: string, args: string[], options: Object }}
29
- */
30
- export function winArgvSpawnSpec( file, args, comspec = process.env.ComSpec || process.env.comspec || 'cmd.exe' ) {
31
- const shellCommand = [ escapeWinCommand( file ), ...args.map( escapeWinArgument ) ].join( ' ' )
32
- return {
33
- file: comspec,
34
- args: [ '/d', '/s', '/c', `"${shellCommand}"` ],
35
- options: { shell: false, windowsVerbatimArguments: true },
36
- }
37
- }
38
-
39
6
  function spawnArgv( file, args, spawnOpts ) {
40
7
  if ( process.platform !== 'win32' ) {
41
8
  return spawn( file, args, { ...spawnOpts, shell: false } )
42
9
  }
43
10
 
44
- const spec = winArgvSpawnSpec( file, args )
45
- return spawn( spec.file, spec.args, { ...spawnOpts, ...spec.options } )
11
+ return spawn( file, args, { ...spawnOpts, shell: true } )
46
12
  }
47
13
 
48
14
  /**
@@ -3,11 +3,11 @@
3
3
  * TASK-005: argv is not interpolated through a shell.
4
4
  */
5
5
  import assert from 'node:assert/strict'
6
- import { existsSync, rmSync } from 'node:fs'
6
+ import { existsSync, readFileSync, rmSync } from 'node:fs'
7
7
  import { tmpdir } from 'node:os'
8
8
  import { join } from 'node:path'
9
9
  import { test } from 'node:test'
10
- import { execCommand, runCommand, winArgvSpawnSpec } from '../src/utilities/shell.js'
10
+ import { execCommand, runCommand } from '../src/utilities/shell.js'
11
11
 
12
12
  function execOnce( command ) {
13
13
  return new Promise( ( resolve ) => {
@@ -131,23 +131,10 @@ test( 'execCommand does not ENOBUFS on stdout larger than 1MB', async () => {
131
131
  }
132
132
  } )
133
133
 
134
- test( 'Windows argv spawn uses cmd.exe so PATHEXT commands like wp.cmd resolve', () => {
135
- const spec = winArgvSpawnSpec( 'wp', [ 'i18n', 'make-pot' ], 'C:\\Windows\\system32\\cmd.exe' )
136
- assert.equal( spec.file, 'C:\\Windows\\system32\\cmd.exe' )
137
- assert.deepEqual( spec.args.slice( 0, 3 ), [ '/d', '/s', '/c' ] )
138
- assert.match( spec.args[3], /wp/ )
139
- assert.equal( spec.options.windowsVerbatimArguments, true )
140
- assert.equal( spec.options.shell, false )
141
- } )
142
-
143
- test( 'Windows argv spawn escapes cmd metacharacters so headers and injection stay literal', () => {
144
- const spec = winArgvSpawnSpec(
145
- 'wp',
146
- [ '--headers={"Last-Translator":"A <b@c.com>"}', '& echo pwned' ],
147
- 'cmd.exe'
148
- )
149
- const line = spec.args[3]
150
- assert.match( line, /\^</ )
151
- assert.match( line, /\^>/ )
152
- assert.match( line, /\^&/ )
134
+ test( 'Windows argv spawn uses a shell so PATHEXT commands like wp.cmd resolve', () => {
135
+ const src = readFileSync( new URL( '../src/utilities/shell.js', import.meta.url ), 'utf8' )
136
+ const spawnArgv = src.split( 'function spawnArgv' )[1].split( 'export function' )[0]
137
+ assert.match( spawnArgv, /process\.platform !== 'win32'/ )
138
+ assert.match( spawnArgv, /shell:\s*false/ )
139
+ assert.match( spawnArgv, /shell:\s*true/ )
153
140
  } )