flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com.INVALID>
Subject Re: [FlexJS] String.match()
Date Thu, 20 Jul 2017 21:00:57 GMT
I think I'm still confused.  My current thinking is that in Flash there
are strings you can pass in that are "invalid RegExp" that will still find
matches in a string.  Isn't that what Yishay showed?  IOW, passing in just
"?" in Flash will find question marks in a string but is an error in JS
because it isn't valid RegExp.

So, right now I think the utility function needs to catch the error and
either escape the string so it is valid RegExp and call match() or use
indexOf() and compute the same result.  It should not always return null.
Then I think it would completely implement how it worked in Flash and the
users won't have to figure out how to regex-ify the strings in the apps
they are porting.

My 2 cents,

On 7/20/17, 12:55 PM, "Harbs" <harbs.lists@gmail.com> wrote:

>After all this discussion, I’m having second thoughts about this whole
>What’s the point of using an invalid RegExp that will not match anything?
>I think the JS behavior makes more sense than the Flash behavior. If a
>RegExp is invalid, it should throw an error rather than never matching
>anything. The use of such a RegExp in the first place can only be
>described as a bug.
>“Fixing” the JS behavior to match the Flash behavior is the wrong thing
>to do.
>> On Jul 20, 2017, at 10:34 PM, Harbs <harbs.lists@gmail.com> wrote:
>> new RegExp({})
>> returns:
>> /[object Object]/
>> I think the wrapping that I did in the code I already committed is
>> try{return input.match(pattern);}
>> catch (e:Error){return null;}
>> If the try fails, that means the RegExp is an invalid expression and
>>will not match anything in Flash. In that case, match should always
>>return null and search should always return -1.
>> I do think that warning developers against using strings is a good
>>idea. Accepting any value and automatically converting it to RegExp
>>seems like a poorly conceived idea to me...
>>> On Jul 20, 2017, at 9:48 PM, Alex Harui <aharui@adobe.com.INVALID
>>><mailto:aharui@adobe.com.INVALID>> wrote:
>>> I'm confused.  Doesn't Yishay's example use syntax that Harbs claimed
>>> threw an error?
>>> Anyway, I can believe the three steps Harbs listed are correct for JS
>>> since step 1 might just happen via implicit type coercion. I suppose
>>> someone could test it by seeing if JS handles "new RegExp({})";
>>> But since there are differences between SWF and JS I want to first make
>>> sure we have agreement that the goal here is to be backward compatible
>>> with SWF if we can.  I don't think we should be requiring folks to
>>> existing passing of strings or getting the compiler to try to modify
>>> strings if we can figure out how to get match() in JS to be equivalent
>>> SWF's match().
>>> So I think Herbs suggested wrapping in try catch like this, correct?
>>> public function match(input:String, pattern:*):Array
>>> {
>>>  {
>>>    return input.match(pattern);
>>>  }
>>>  {
>>>    try
>>>    {
>>>      return input.match(pattern);
>>>    }
>>>    catch (e:Error)
>>>    {
>>>      pattern = pattern.toString();
>>>      if (input.indexOf(pattern) != -1)
>>>        return [ pattern ]; // or whatever should be returned
>>>      return null;
>>>    }
>>>  }
>>> }
>>> I don't think we should use trace to tell folks not to use String.  You
>>> are welcome to add it to the ASDoc though.
>>> -Alex
>>> On 7/20/17, 10:52 AM, "yishayw" <yishayjobs@hotmail.com
>>><mailto:yishayjobs@hotmail.com>> wrote:
>>>> I think there would still be a difference between flash and js
>>>>because the
>>>> flash implementation (counter to AS3 documentation) always returns
>>>> when
>>>> an invalid regex is passed as a string. So according to your suggested
>>>> implementation for
>>>> Var s: String = "m?o";
>>>> Var a:Array = s.match("?")
>>>> a  is null in flash but ["?"] in JS.
>>>> --
>>>> View this message in context:
>>>> x-development.2333347.n4.nabble.com
>>>> UQHenXZDXmu0lK3PtJ%2FnhetW4%3D&reserved=0
>>>> Sent from the Apache Flex Development mailing list archive at

View raw message