Skip to content
This repository has been archived by the owner. It is now read-only.

[IDE] JS regex replace for line break does not work with 1.0.11 and Firefox 4 #1816

Open
lukeis opened this issue Mar 2, 2016 · 8 comments
Open

Comments

@lukeis
Copy link
Member

@lukeis lukeis commented Mar 2, 2016

Originally reported on Google Code with ID 1816

I'm using StoreEval to run a JS function that strips line breaks out of the selected
section of code. I've had no problems with 1.0.10 and Firefox 3.6. Now that 1.0.11
was released with FF4 support, I decided to validate the scripts against a VM instead
of upgrading both FF and IDE right away.

Here is a simplified sample of my jsfunction:

function test() { var temp = 'test        text'; temp = temp.replace(/(\\n)/g, "");
return(temp); } test();

Selenium always seems to rewrite the regex as (/(\\\n)/g, ""); but since it does this
in all cases I tested, I don't think this is part of the issue.
I have to use \\n when using the regex in Selenium IDE, which you are probably aware
of.

When I run this function in IDE 1.0.11 and FF4, I get the following error from Selenium:
[error] Threw an exception: unterminated regular expression literal

I even tried using IDE 1.0.11 with Firefox 3.6, the command works perfectly.

The IDE 1.0.11 and FF4 combination fails on both XP and Windows 7, I don't believe
it's operating system related.

I've attached the simple test case for you to try out.

Reported by jdungan on 2011-06-10 16:17:23


- _Attachment: [sample.html](https://storage.googleapis.com/google-code-attachments/selenium/issue-1816/comment-0/sample.html)_
@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by david.burns@theautomatedtester.co.uk on 2011-07-22 20:42:31

  • Labels added: Component-IDE
@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by david.burns@theautomatedtester.co.uk on 2011-08-31 16:29:59

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

This is still an issue in Selenium IDE 1.3.0 and Firefox 7

Reported by jdungan on 2011-09-30 16:43:35

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

This issue is still present in Selenium IDE 2.8.0 and Firefox 33. It's not restricted
to regular expressions. It applies to any presence of \n in 'target' or 'value' columns.
That restricts usability of getEval and similar commands that evaluate contents of
'target' (and/or 'value') as Javascript.

Using \\n in string constants doesn't help. Once I switch to edit another command in
the test case, Selenium IDE changes '\\n' to '\\\n'. And '\n' is not passed to Javascript:
| getEval | alert('hi\\\nmate') | will show a message 'himate'.

Reported by peter.kehl on 2014-10-30 05:22:17

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Selenium IDE 2.8.0 and Firefox 35.0.1: The issue is present if the \n is in the Target.
However, there is no issue if the \n is in the Value (for verifyText/waitForText commands
at least)

Reported by oleksiid@google.com on 2015-02-10 23:35:13

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

I faced a similar problem. This is a possible work around to remove the new line character:
(1) Escape the string, (2) replace the escaped new line character (%0A) with blank,
(2) then unescape back to the original value, eg: 

storeEval | unescape(escape(storedVars['has_new_line']).replace(/%0A/g,'')) | no_nl

This new line character appears to have come from HTML break <br /> that is rendered
by the browser, then extracted by Selenium IDE as \n. 

Reported by saengch on 2015-03-20 03:32:27

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

@peter.kehl I was having the same problem with a javascript alert within Selenium IDE
2.9.0, and the workaround I found was to use \\u000A as the newline character.  So
for your example: | getEval | alert('hi\\\nmate') | 
becomes: | getEval | alert('hi\\u000Amate') |

That did the trick for me...

Reported by libby.steven on 2015-06-12 13:43:40

@lukeis
Copy link
Member Author

@lukeis lukeis commented Mar 2, 2016

Reported by luke.semerau on 2015-09-17 17:44:24

  • Labels added: Restrict-AddIssueComment-Commit
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant