Permalink
Browse files

Escape multi-line console messages

Fixes #411
  • Loading branch information...
1 parent c155b37 commit 40a8bec85422b7d8c7f8ee2ce6a169150cc76e70 @mhoran mhoran committed Nov 15, 2012
Showing with 9 additions and 4 deletions.
  1. +1 −1 lib/capybara/webkit/browser.rb
  2. +7 −2 spec/driver_spec.rb
  3. +1 −1 src/WebPage.cpp
@@ -45,7 +45,7 @@ def status_code
def console_messages
command("ConsoleMessages").split("\n").map do |messages|
parts = messages.split("|", 3)
- { :source => parts.first, :line_number => Integer(parts[1]), :message => parts.last }
+ { :source => parts.first, :line_number => Integer(parts[1]), :message => parts.last.gsub("\\n", "\n") }
end
end
View
@@ -425,6 +425,7 @@ def in_iframe_request?
<script type="text/javascript">
console.log("hello");
console.log("hello again");
+ console.log("hello\\nnewline");
oops
</script>
</body>
@@ -440,18 +441,22 @@ def in_iframe_request?
message.should include :source => url, :message => "hello"
# QtWebKit returns different line numbers depending on the version
[5, 6].should include(message[:line_number])
- driver.console_messages.length.should eq 3
+ driver.console_messages.length.should eq 4
end
it "logs errors to the console" do
driver.error_messages.length.should eq 1
end
+ it "supports multi-line console messages" do
+ message = driver.console_messages[2]
+ message[:message].should == "hello\nnewline"
+ end
+
it "empties the array when reset" do
driver.reset!
driver.console_messages.should be_empty
end
-
end
context "javascript dialog interaction" do
View
@@ -134,7 +134,7 @@ QVariant WebPage::invokeCapybaraFunction(QString &name, const QStringList &argum
}
void WebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) {
- QString fullMessage = QString::number(lineNumber) + "|" + message;
+ QString fullMessage = QString::number(lineNumber) + "|" + QString(message).replace("\n", "\\n");;
if (!sourceID.isEmpty())
fullMessage = sourceID + "|" + fullMessage;
m_consoleMessages.append(fullMessage);

0 comments on commit 40a8bec

Please sign in to comment.