<i>'TCL_REG_CANMATCH' flag returns incorrect matches</i> status still Open with 8 other changes
by
.
D 2015-11-06T21:04:46.288
J assignee aku
J closer nobody
J comment The\sattached\spatch\sto\stclTest.c\sand\sreg.test\sshows\s\r\nhow\sTcl_RegExpExecObj\sreturns\sincorrect\smatches\s\r\nfor\smany,\smany\scases\susing\sthe\s'TCL_CAN_MATCH'\s\r\nflag.\r\n\r\nThis\sflag\sis\ssupposed\sto\smake\sregexp\sreturn\s(if\sit\s\r\ncan't\sfind\sa\scomplete\smatch)\sthe\sfirst\spossible\s\r\nposition\sat\swhich\sa\smatch\scould\soccur.\s\sHowever,\sit\s\r\nreturns\spositions\sat\swhich\sit\sis\squite\sobvious\sno\s\r\nmatch\scould\sever\soccur!\r\n\r\nFor\sexample:\r\n\r\n\s\s\s\sset\spat\s{.x}\r\n\s\s\s\sset\sline\s"asd\sasd"\r\n\s\s\s\s#\scan\smatch\sthe\slast\schar,\sif\sfollowed\sby\sx\r\n\s\s\s\sset\sres\s[testregexp\s-xflags\s--\sc\s$pat\s$line\sresvar]\r\n\s\s\s\slappend\sres\s$resvar\r\n\r\nShould\sreturn\s'0\s6'\sto\ssay\sthere\sis\sno\smatch\s(0)\sbut\s\r\na\smatch\scould\spossible\soccur\sat\sposition\s6\s(with\s'.'\s\r\nmatching\sthe\sfinal\s'd',\sif\san\s'x'\swas\sto\sbe\sappended\s\r\nto\sthe\sstring).\r\n\r\nUnfortunately\sit\sreturns\s'0\s0'\swhich\sis\squite\swrong.
J icomment I\sam\snot\ssure\sthat\sthere\sis\sany\sworkable\ssolution\sto\sthis.\s\sThe\sproblem\sis\sthat\syou're\srelying\son\sthe\s"cold\sstart"\sposition\sreturned\sby\sshortest(),\swhich\sis\san\simplementation\sdetail\sthat\sshould\sprobably\snever\shave\sbeen\sexposed\soutside\sthe\sregexp\sengine.\s\sIt\sdoesn't\shave\sany\smeaningful\svalue\sfor\scases\slike\sthis,\sbecause\sit\sreports\son\sthe\slast\splace\swhere\sthere\swas\sno\sactive\sNFA\sstate\srepresenting\spartial\straversal\sof\sthe\sregexp.\s\sGiven\sa\sregexp\sstarting\swith\s'.',\severy\scharacter\scan\smatch\sthat,\sand\sso\severy\sstring\sposition\sbeyond\sstart-of-string\swill\shave\san\sactive\sNFA\sstate\sindicating\sthat\swe\ssuccessfully\straversed\sthe\s'.'.\s\sNow,\sunless\sthe\snext\scharacter\sis\s'x'\swe\swill\sfail\sto\sfind\sany\stransition\sout\sof\sthat\sNFA\sstate\sso\sit\sgives\srise\sto\sno\sactive\sstate\safter\sconsuming\sthe\snext\scharacter\s---\sbut\smeanwhile\swe\smatched\s'.'\sagain,\sso\sthere's\sa\snew\sinstance\sof\sthe\ssame\sactive\sNFA\sstate\sinstead.\s\sThere's\sno\sway\sto\sget\sto\sa\scold-start\scondition\sas\slong\sas\sincomplete\smatches\soverlap,\sor\seven\sjust\sare\sadjacent.\r\n\r\nI\sdon't\spresently\ssee\sany\sway\saround\sthat\sexcept\sto\stry\sto\strack\sthe\smatch-start\sposition(s)\sassociated\swith\seach\sactive\sNFA\sstate,\swhich\sseems\scompletely\simpractical,\sand\scertainly\swould\sbe\sdisastrous\sfor\sstring\smatching\sspeed\seven\sif\sit\scould\sbe\sdone\sin\sa\ssane\samount\sof\smemory.\r\n\r\nSo\sAFAICS\sthe\scold-start\slogic\sis\sjust\sa\sheuristic\smeant\sto\sreduce\sthe\samount\sof\sbrute-force\ssearching\sdone\sin\ssimpleFind()\sor\scomplicatedFindLoop(),\sand\sit\swas\sa\smistake\sto\simagine\sthat\sit\shad\ssemantics\suseful\sto\soutside\scallers.
J login tgl
J mimetype text/plain
J severity Minor
J title 'TCL_REG_CANMATCH'\sflag\sreturns\sincorrect\smatches
K 703709ffffffffffffffffffffffffffffffffff
U tgl
Z bc9f474e1b1419df98ee002cf84b8e1d