Possible issue when using parseInt function

How to force integers not to be octals in PHP applications

Paul Synnott recently pointed out that there was a potential issue in some of the code we had written.  It involved using the parseInt function of JavaScript in order to ensure we are dealing with integer values.

He noticed that if you pass a string of ‘09’ the function will attempt to treat the value as an octal (which is a fairly unsafe thing to have as a default in my opinion) in order to fix this you would change:

var test = parseInt('09');

to

var test = parseInt('09',10);

This will force base 10 to be used instead of octal.


Recent posts View all

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.