aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/reline/config.rb10
-rw-r--r--test/reline/test_config.rb5
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 5c10d7fa91..09e572561c 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -5,6 +5,8 @@ class Reline::Config
DEFAULT_PATH = '~/.inputrc'
+ KEYSEQ_PATTERN = /\\C-[A-Za-z_]|\\M-[0-9A-Za-z_]|\\C-M-[A-Za-z_]|\\M-C-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./
+
class InvalidInputrc < RuntimeError
attr_accessor :file, :lineno
end
@@ -137,9 +139,10 @@ class Reline::Config
next
end
- if line =~ /\s*(.*)\s*:\s*(.*)\s*$/
+ if line =~ /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/
key, func_name = $1, $2
keystroke, func = bind_key(key, func_name)
+ next unless keystroke
@additional_key_bindings[keystroke] = func
end
end
@@ -227,7 +230,7 @@ class Reline::Config
end
def bind_key(key, func_name)
- if key =~ /"(.*)"/
+ if key =~ /\A"(.*)"\z/
keyseq = parse_keyseq($1)
else
keyseq = nil
@@ -277,9 +280,8 @@ class Reline::Config
def parse_keyseq(str)
# TODO: Control- and Meta-
ret = []
- while str =~ /(\\C-[A-Za-z_]|\\M-[0-9A-Za-z_]|\\C-M-[A-Za-z_]|\\M-C-[A-Za-z_]|\\e|\\\\|\\"|\\'|\\a|\\b|\\d|\\f|\\n|\\r|\\t|\\v|\\\d{1,3}|\\x\h{1,2}|.)/
+ str.scan(KEYSEQ_PATTERN) do
ret << key_notation_to_code($&)
- str = $'
end
ret
end
diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb
index ee006b72dc..58f265d817 100644
--- a/test/reline/test_config.rb
+++ b/test/reline/test_config.rb
@@ -33,6 +33,11 @@ class Reline::Config::Test < Reline::TestCase
assert_not_include @config.key_bindings, nil
end
+ def test_invalid_keystroke
+ @config.read_lines(["a: error\n"])
+ assert_not_include @config.key_bindings, nil
+ end
+
def test_bind_key
assert_equal ['input'.bytes, 'abcde'.bytes], @config.bind_key('"input"', '"abcde"')
end