From 0a6886f37a40101306e15b5f50e22dfa57c1fe49 Mon Sep 17 00:00:00 2001 From: William Morgan Date: Mon, 21 Jan 2008 23:29:46 -0800 Subject: [PATCH] escape all regexes used for tab completion Tab completion uses many regexes, all built from user data. These need to be escaped, or special characters will throw an exception. --- lib/sup/buffer.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index 2a78787..4374fa8 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -398,7 +398,7 @@ EOS def ask_with_completions domain, question, completions, default=nil ask domain, question, default do |s| - completions.select { |x| x =~ /^#{s}/i }.map { |x| [x, x] } + completions.select { |x| x =~ /^#{Regexp::escape s}/i }.map { |x| [x, x] } end end @@ -414,7 +414,7 @@ EOS raise "william screwed up completion: #{partial.inspect}" end - completions.select { |x| x =~ /^#{target}/i }.map { |x| [prefix + x, x] } + completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] } end end @@ -423,7 +423,7 @@ EOS prefix, target = partial.split_on_commas_with_remainder target ||= prefix.pop || "" prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ") - completions.select { |x| x =~ /^#{target}/i }.map { |x| [prefix + x, x] } + completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] } end end @@ -436,7 +436,7 @@ EOS if dir [[s.sub(full, dir), "~#{name}"]] else - users.select { |u| u =~ /^#{name}/ }.map do |u| + users.select { |u| u =~ /^#{Regexp::escape name}/ }.map do |u| [s.sub("~#{name}", "~#{u}"), "~#{u}"] end end -- 2.45.2