diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 18:54:50 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-04 18:54:50 +0900 |
commit | 265b9a0edf48e96d053724c9676af953e920246c (patch) | |
tree | 85dee32522a7e0454966b2e7f8f0d6b77dda43e4 /lib | |
parent | 12e06d32f55dff7f35c66842e5d6901857132060 (diff) | |
download | ruby-265b9a0edf48e96d053724c9676af953e920246c.tar.gz |
Parse key sequence more strictly
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/config.rb | 10 |
1 files changed, 6 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 |