flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harbs <harbs.li...@gmail.com>
Subject Re: [FlexJS] String.match()
Date Fri, 21 Jul 2017 15:01:56 GMT
lists.apache.org <http://lists.apache.org/> displays it fine:
https://lists.apache.org/thread.html/ec0b951752140ad0cd56319b9629cc4a7e097487fd47c84649ffc352@%3Cdev.flex.apache.org%3E
<https://lists.apache.org/thread.html/ec0b951752140ad0cd56319b9629cc4a7e097487fd47c84649ffc352@%3Cdev.flex.apache.org%3E>

I think you missed my last point.

The fact that JS throws an error actually uncovered a bug in my code. When you construct an
invalid regex in Flash, you get a RegExp object which will NEVER match anything. It’s a
valid RegExp object with an invalid expression. That’s nonsensical. There’s no legitimate
reason to use a regex which does nothing.

The JS behavior which throws an error makes much more sense, so I’m currently of the opinion
that we shouldn’t be fixing this at all.

Harbs

> On Jul 21, 2017, at 5:13 PM, Alex Harui <aharui@adobe.com.INVALID> wrote:
> 
> My email totally mangled your post.  Anyway, if you think you've got code
> that is equivalent to Flash's  String.match, that's good enough for now.
> If folks find issues later we can improve on the utility function.
> 
> If you want to alter the compiler output, see how I handled Array.sortOn
> in FunctionCallEmitter.java.  I think you can do something similar for
> String.match and String.search.
> 
> Thanks,
> -Alex
> 
> On 7/20/17, 2:28 PM, "Harbs" <harbs.lists@gmail.com <mailto:harbs.lists@gmail.com>>
wrote:
> 
>> No. We thought that the “?” found the string in Flash. It does not.
>> 
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww>
>> w.google.com <http://w.google.com/>%2Fsearch%3Fq%3Ddogs&data=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D&reserved=0".match("
>> ?"));
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww>
>> w.google.com <http://w.google.com/>%2Fsearch%3Fq%3Ddogs&data=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D&reserved=0".search(
>> "?"));
>> trace("https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fww>
>> w.google.com <http://w.google.com/>%2Fsearch%3Fq%3Ddogs&data=02%7C01%7C%7Ce68f4223e52d48e8c03908d
>> 4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&
>> sdata=voY1pLBiaj2u1GDu0YeKMipu%2FGRHwMWQzRRA0JCTkZc%3D&reserved=0".indexOf
>> ("?"));
>> 
>> outputs:
>> 
>> null
>> -1
>> 29
>> 
>>> On Jul 21, 2017, at 12:00 AM, Alex Harui <aharui@adobe.com.INVALID <mailto:aharui@adobe.com.INVALID>>
>>> wrote:
>>> 
>>> 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,
>>> -Alex
>>> 
>>> 
>>> 
>>> On 7/20/17, 12:55 PM, "Harbs" <harbs.lists@gmail.com <mailto:harbs.lists@gmail.com>
>>> <mailto:harbs.lists@gmail.com <mailto:harbs.lists@gmail.com>>>
wrote:
>>> 
>>>> After all this discussion, I’m having second thoughts about this whole
>>>> thing.
>>>> 
>>>> 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 <mailto:harbs.lists@gmail.com>>
wrote:
>>>>> 
>>>>> new RegExp({})
>>>>> returns:
>>>>> /[object Object]/
>>>>> 
>>>>> I think the wrapping that I did in the code I already committed is
>>>>> correct:
>>>>> 
>>>>> 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>
>>>>>> <mailto:aharui@adobe.com.INVALID <mailto:aharui@adobe.com.INVALID>
<mailto: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
>>>>>> modify
>>>>>> existing passing of strings or getting the compiler to try to modify
>>>>>> those
>>>>>> strings if we can figure out how to get match() in JS to be
>>>>>> equivalent
>>>>>> to
>>>>>> SWF's match().
>>>>>> 
>>>>>> So I think Herbs suggested wrapping in try catch like this, correct?
>>>>>> 
>>>>>> public function match(input:String, pattern:*):Array
>>>>>> {
>>>>>> COMPILE::SWF
>>>>>> {
>>>>>>  return input.match(pattern);
>>>>>> }
>>>>>> COMPILE::JS
>>>>>> {
>>>>>>  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>
>>>>>> <mailto:yishayjobs@hotmail.com <mailto:yishayjobs@hotmail.com>>
>>>>>> <mailto:yishayjobs@hotmail.com <mailto:yishayjobs@hotmail.com>
<mailto: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
>>>>>>> null
>>>>>>> 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:
>>>>>>> 
>>>>>>> 
>>>>>>> https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapach
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapach>
>>>>>>> e- 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac>
>>>>>>> he->
>>>>>>> fle 
>>>>>>> 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac>
>>>>>>> he 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapac>
>>>>>>> he>
>>>>>>> -fle>
>>>>>>> x-development.2333347.n4.nabble.com <http://x-development.2333347.n4.nabble.com/>
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de>
>>>>>>> velopment.2333347.n4.nabble.com <http://velopment.2333347.n4.nabble.com/>%2F&data=02%7C01%7C%7Ce68f4223e52d48e8
>>>>>>> c03908d4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C6363618
>>>>>>> 29356324151&sdata=TG6M8KryM8pQq0jjjBGCjM30i4j8R78tIYwdKo9S9o4%3D&rese
>>>>>>> rved=0>
>>>>>>> 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de>
>>>>>>> ve 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fx-de>
>>>>>>> ve>
>>>>>>> lopment.2333347.n4.nabble.com <http://lopment.2333347.n4.nabble.com/>
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flopm
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flopm>
>>>>>>> ent.2333347.n4.nabble.com <http://ent.2333347.n4.nabble.com/>%2F&data=02%7C01%7C%7Ce68f4223e52d48e8c03908
>>>>>>> d4cfb6524c%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C6363618293563
>>>>>>> 24151&sdata=n7GTeuktiyF%2FrxSvm%2BtZqbcZ1RlX6xbLT8PXnFjkMhk%3D&reserv
>>>>>>> ed=0>%2F&data=02%7C01%7C%7C6ec68d20c01e4fae6173
>>>>>>> 
>>>>>>> 08d4cfa95280%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C63636177351
>>>>>>> 99
>>>>>>> 
>>>>>>> 74472&sdata=UiouHqnKJ4SI1gEcaeu9N5%2FHqGYle%2FKELTCvKRo8c8c%3D&reserv
>>>>>>> ed
>>>>>>> =0>%2FFlexJS-String-match-tp63392p63467.ht
>>>>>>> 
>>>>>>> 
>>>>>>> ml&data=02%7C01%7C%7C381f79bbe2594b1cab0808d4cf9af1a0%7Cfa7b1b5a7b344
>>>>>>> 38
>>>>>>> 794
>>>>>>> 
>>>>>>> 
>>>>>>> aed2c178decee1%7C0%7C0%7C636361711762211281&sdata=gA2I9N%2Bq%2F%2FvIL
>>>>>>> p7
>>>>>>> C3c
>>>>>>> UQHenXZDXmu0lK3PtJ%2FnhetW4%3D&reserved=0
>>>>>>> Sent from the Apache Flex Development mailing list archive at
>>>>>>> Nabble.com <http://nabble.com/> 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb>
>>>>>>> le.com <http://le.com/>%2F&data=02%7C01%7C%7Ce68f4223e52d48e8c03908d4cfb6524c%7Cfa7b1b
>>>>>>> 5a7b34438794aed2c178decee1%7C0%7C0%7C636361829356324151&sdata=wstsyap
>>>>>>> Iw9kn5y22ZFoCDiYuBb%2FGD0h5PX0OEPLHcWU%3D&reserved=0>
>>>>>>> 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb>
>>>>>>> le 
>>>>>>> <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb
<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fnabb>
>>>>>>> le>
>>>>>>> 
>>>>>>> .com%2F&data=02%7C01%7C%7C6ec68d20c01e4fae617308d4cfa95280%7Cfa7b1b5a
>>>>>>> 7b
>>>>>>> 
>>>>>>> 34438794aed2c178decee1%7C0%7C0%7C636361773519974472&sdata=1Eu83yHYa6T
>>>>>>> aL
>>>>>>> rDm0RmuENLfQREVxolgz4%2BbWUgKB9c%3D&reserved=0>.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message