mirror of
https://github.com/samsonjs/csc360-a1-shell.git
synced 2026-04-27 14:57:43 +00:00
Fix StandardRB in word expander
This commit is contained in:
parent
7cddb9393d
commit
d6ded9dd46
1 changed files with 8 additions and 11 deletions
|
|
@ -53,8 +53,7 @@ module Shell
|
||||||
field = "".dup
|
field = "".dup
|
||||||
at_word_start = true
|
at_word_start = true
|
||||||
found_glob_char = false
|
found_glob_char = false
|
||||||
line.scan(/\G\s*(?>([^\0\s\\'"]+)|'([^\0']*)'|"((?:[^\0"\\]|\\[^\0])*)"|(\\[^\0]?)|(\S))(\s|\z)?/m) do
|
line.scan(/\G\s*(?>([^\0\s\\'"]+)|'([^\0']*)'|"((?:[^\0"\\]|\\[^\0])*)"|(\\[^\0]?)|(\S))(\s|\z)?/m) do |word, sq, dq, esc, garbage, sep|
|
||||||
|word, sq, dq, esc, garbage, sep|
|
|
||||||
if garbage
|
if garbage
|
||||||
b = $~.begin(0)
|
b = $~.begin(0)
|
||||||
line = $~[0]
|
line = $~[0]
|
||||||
|
|
@ -106,7 +105,7 @@ module Shell
|
||||||
name = m[1]
|
name = m[1]
|
||||||
fallback = m[2]
|
fallback = m[2]
|
||||||
env_value = ENV[name]
|
env_value = ENV[name]
|
||||||
env_value.nil? || env_value.empty? ? expand_variables(fallback) : env_value
|
(env_value.nil? || env_value.empty?) ? expand_variables(fallback) : env_value
|
||||||
else
|
else
|
||||||
ENV.fetch(raw)
|
ENV.fetch(raw)
|
||||||
end
|
end
|
||||||
|
|
@ -178,7 +177,11 @@ module Shell
|
||||||
if i + 1 < line.length
|
if i + 1 < line.length
|
||||||
escaped = line[i + 1]
|
escaped = line[i + 1]
|
||||||
if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\""
|
if escaped == "$" || escaped == "`" || escaped == "\\" || escaped == "\""
|
||||||
output << (escaped == "$" ? ESCAPED_DOLLAR : (escaped == "`" ? ESCAPED_BACKTICK : escaped))
|
output << (if escaped == "$"
|
||||||
|
ESCAPED_DOLLAR
|
||||||
|
else
|
||||||
|
((escaped == "`") ? ESCAPED_BACKTICK : escaped)
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
output << "\\"
|
output << "\\"
|
||||||
output << escaped
|
output << escaped
|
||||||
|
|
@ -241,20 +244,15 @@ module Shell
|
||||||
case c
|
case c
|
||||||
when "("
|
when "("
|
||||||
depth += 1
|
depth += 1
|
||||||
output << c
|
|
||||||
when ")"
|
when ")"
|
||||||
depth -= 1
|
depth -= 1
|
||||||
return [output, i + 1] if depth.zero?
|
return [output, i + 1] if depth.zero?
|
||||||
output << c
|
|
||||||
when "'"
|
when "'"
|
||||||
state = :single_quoted
|
state = :single_quoted
|
||||||
output << c
|
|
||||||
when "\""
|
when "\""
|
||||||
state = :double_quoted
|
state = :double_quoted
|
||||||
output << c
|
|
||||||
else
|
|
||||||
output << c
|
|
||||||
end
|
end
|
||||||
|
output << c
|
||||||
when :single_quoted
|
when :single_quoted
|
||||||
output << c
|
output << c
|
||||||
state = :unquoted if c == "'"
|
state = :unquoted if c == "'"
|
||||||
|
|
@ -297,6 +295,5 @@ module Shell
|
||||||
end
|
end
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue