Board index FlightGear Development Nasal

Possible bug in string.match

Nasal is the scripting language of FlightGear.

Possible bug in string.match

Postby ThomasS » Fri Jun 01, 2018 6:46 am

Hello,

running the code

Code: Select all
if (string.match("747","747*") ) print ("matches"); else print("doesn't match");


prints "doesn't match" (FG2018.2). But as stated in the wiki, '*' stands for any number (including zero) of arbitrary characters. Am I wrong here or should we consider this to be a bug?

Best Regards

Thomas
ThomasS
 
Posts: 94
Joined: Sun Sep 11, 2016 2:21 pm
Location: West of EDDK
Version: 2018.2.1
OS: Linux,MacOS,Windows

Re: Possible bug in string.match

Postby wkitty42 » Fri Jun 01, 2018 11:11 am

confirmed with 2018.3.0...

Code: Select all
string.match("747","747*")  doesn't match
string.match("747","*747")  matches
string.match("747","*747*") doesn't match


looks like the parsing to break out the wild card isn't working right... i would say that it is a bug... are you going to file a report in the bug tracker?
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9146
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: Possible bug in string.match

Postby ThomasS » Sat Jun 02, 2018 2:30 pm

Thanks for your comment. I created ticket #2016.
ThomasS
 
Posts: 94
Joined: Sun Sep 11, 2016 2:21 pm
Location: West of EDDK
Version: 2018.2.1
OS: Linux,MacOS,Windows

Re: Possible bug in string.match

Postby Necolatis » Sat Jun 02, 2018 2:55 pm

Your test case is wrong.

That function output -1 if not found.
So since 747 is at start of string it output 0, which you evaluate as false. Hence you think it wasn't found, but it was.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Possible bug in string.match

Postby Necolatis » Sat Jun 02, 2018 3:05 pm

Oops I was thinking of find(). nevermind.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10


Return to Nasal

Who is online

Users browsing this forum: No registered users and 4 guests