web stats
Puzzling Javascript Error in Regexp on Mirth 1.8.2.4472 - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 08-16-2019, 12:03 PM
bassicallychris bassicallychris is offline
Mirth Newb
 
Join Date: Sep 2018
Posts: 11
bassicallychris is on a distinguished road
Default

Thank you for the explanation! That makes a lot of sense to me, I'm still fuzzy on why the distinction needed to be made when using a variable that directly represents a string passed to the function vs. not needed when iterationing through an object passed to the function resulting in using
Code:
object[property]
which also directly represents a string.
Reply With Quote
  #12  
Old 08-16-2019, 05:40 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 894
agermano is on a distinguished road
Default

When using typeof on a js primitive string it returns 'string'. typeof on an instance of java.lang.String will return 'object'.
Reply With Quote
  #13  
Old 08-18-2019, 08:57 AM
bassicallychris bassicallychris is offline
Mirth Newb
 
Join Date: Sep 2018
Posts: 11
bassicallychris is on a distinguished road
Default

This makes sense, I think my initial message caused confusion because in reality I was using the string variable without appending ` "" ` to it but I believe I've still understood this.

To confirm, there are JavaScript and Java replace functions that are written differently and Rhino doesn't know which one to use unless the string is explicitly defined as either a JS or Java string. When performing the typeof evaluation you're letting Rhino know that you're using a JS string but if you just feed it a string it doesn't know which replace function to use.
Reply With Quote
  #14  
Old 08-19-2019, 08:42 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 894
agermano is on a distinguished road
Default

If you pass a javascript regular expression as the first parameter, it will work if you're calling it on a javascript string, and it won't work on a java string, because it's expecting either a char or CharSequence as the first parameter, and Rhino can't tell which one you meant to call.

If you pass strings as both parameters, it will work because both the java and js methods behave the same way in this case, and the javascript strings will get converted to CharSequences when called on a java string, so it's not ambiguous like when passing a regex.
Reply With Quote
Reply

Tags
javascript, regexp

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:33 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation