Skip to content
Browse files

Don't rstrip strings [Fixes #657]

Rstripping was there to keep things neat and tidy, unfortunately it's
possible to have some ruby code where whitespace is significant.

I've left the lstripping in because it will not trigger inside a string
and so cannot occlude a closing whitespace delimeter at the start of a
line.
  • Loading branch information...
1 parent cfc5890 commit 94e77efa28143e70ef1562acff79cff19f82d5f4 @ConradIrwin ConradIrwin committed
Showing with 14 additions and 3 deletions.
  1. +1 −2 lib/pry/indent.rb
  2. +1 −1 lib/pry/pry_instance.rb
  3. +12 −0 test/test_syntax_checking.rb
View
3 lib/pry/indent.rb
@@ -129,7 +129,6 @@ def indent(input)
new_prefix = prefix + SPACES * after
line = prefix + line.lstrip unless previously_in_string
- line = line.rstrip + "\n" unless in_string?
output += line
@@ -138,7 +137,7 @@ def indent(input)
@indent_level = prefix
- return output.gsub(/\s+$/, '')
+ return output
end
# Get the indentation for the start of the next line.
View
2 lib/pry/pry_instance.rb
@@ -405,7 +405,7 @@ def retrieve_line(eval_string, target)
begin
if !process_command(val, eval_string, target)
- eval_string << "#{indented_val.rstrip}\n" unless val.empty?
+ eval_string << "#{indented_val}\n" unless val.empty?
end
ensure
Pry.history << indented_val unless input.is_a?(StringIO)
View
12 test/test_syntax_checking.rb
@@ -62,4 +62,16 @@
it "should not clobber _ex_ on a SyntaxError in the repl" do
mock_pry("raise RuntimeError, 'foo';", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m
end
+
+ it "should allow whitespace delimeted strings" do
+ mock_pry('"%s" %% foo ').should =~ /"foo"/
+ end
+
+ it "should allow newline delimeted strings" do
+ mock_pry('"%s" %%','foo').should =~ /"foo"/
+ end
+
+ it "should allow whitespace delimeted strings ending on the first char of a line" do
+ mock_pry('"%s" %% ', ' #done!').should =~ /"\\n"/
+ end
end

0 comments on commit 94e77ef

Please sign in to comment.
Something went wrong with that request. Please try again.