From 62f48d56e092c41dad0e1b54ac11a60a469d6f6d Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sat, 17 Aug 2024 18:38:40 -0700 Subject: [PATCH] Added the `--nodejs` option to `ronin escape` (closes #218). --- lib/ronin/cli/commands/escape.rb | 7 +++++++ man/ronin-escape.1.md | 3 +++ spec/cli/commands/escape_spec.rb | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/lib/ronin/cli/commands/escape.rb b/lib/ronin/cli/commands/escape.rb index 0f93ff1e7..600baab98 100644 --- a/lib/ronin/cli/commands/escape.rb +++ b/lib/ronin/cli/commands/escape.rb @@ -40,6 +40,7 @@ module Commands # -u, --uri URI escapes the data # --http HTTP escapes the data # -j, --js Encodes the data as a JavaScript string + # -n, --nodejs Escapes the data as a Node.js string # -S, --shell Escapes the data as a Shell string # -P, --powershell Escapes the data as a PowerShell string # -Q, --quoted-printable Escapes the data as Quoted Printable @@ -89,6 +90,12 @@ class Escape < StringMethodsCommand @method_calls << :js_escape end + option :nodejs, short: '-n', + desc: 'Escapes the data as a Node.js string' do + require 'ronin/support/encoding/node_js' + @method_calls << :node_js_escape + end + option :shell, short: '-S', desc: 'Escapes the data as a Shell string' do require 'ronin/support/encoding/shell' diff --git a/man/ronin-escape.1.md b/man/ronin-escape.1.md index b4bcced56..9b94d096e 100644 --- a/man/ronin-escape.1.md +++ b/man/ronin-escape.1.md @@ -50,6 +50,9 @@ Escapes each special character for a variety of encodings. `-j`, `--js` : Escapes the data as a JavaScript string. +`-n`, `--nodejs` +: Escapes the data as a Node.js string. + `-S`, `--shell` : Escapes the data as a Shell string. diff --git a/spec/cli/commands/escape_spec.rb b/spec/cli/commands/escape_spec.rb index a4ac9187f..fbbcc4132 100644 --- a/spec/cli/commands/escape_spec.rb +++ b/spec/cli/commands/escape_spec.rb @@ -80,6 +80,18 @@ end end + describe "--nodejs" do + let(:argv) { %w[--nodejs] } + + it "must require 'ronin/support/encoding/node_js'" do + expect(require('ronin/support/encoding/node_js')).to be(false) + end + + it "must add :node_js_escape to #method_calls" do + expect(subject.method_calls.last).to eq(:node_js_escape) + end + end + describe "--shell" do let(:argv) { %w[--shell] }