ColdFusion 9: int and type=“numeric” nasty bug?

允我心安 提交于 2019-12-01 02:04:07

This is a variation on that theme from the other question. See this code (or run it on cflive.net):

<cfscript>
s = "1 2";
i = int(s);
v = isValid("numeric", s);
d = createOdbcDate(s);
writeDump([s,i,v,d]);
</cfscript>

s converts to 41276 when calling int(), and when using it as an input for createOdbcDate(), we get:

January, 02 2013 00:00:00 +0000

So "1 2" is being interpreted as "m d", with an implied year of the current year.

Which is utterly stupid. But there you go.

You can use regular expressions to find out if there are any non numeric characters in a given form field:

reFind( "[^\d-]", "1 2")

That will match any character that is not a number, not a -

If you want to check only positive numbers, you can use

reFind( "[^\d]", "1 2")    

If this returns true, you do not have an integer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!