Improper use of the parseInt javascript function

Bug #1394330 reported by Robert Lyon on 2014-11-19
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
High
Robert Lyon
1.10
High
Unassigned
1.8
High
Unassigned
1.9
High
Unassigned

Bug Description

The parseInt() function needs to specify that it is using radix 10

Older browsers use the octal radix (8) as default so parseInt('010') will return '8' rather than '10' that we might expect.

In many places the function is used correctly, eg: parseInt(match[1], 10);

But not all places are indicating to use a base 10 radix.

So I'll clean up the places it is not used so that we know to return a base 10 number.

Reviewed: https://reviews.mahara.org/3994
Committed: http://gitorious.org/mahara/mahara/commit/3743dcf68d1058f647081cf5d29662181978fd01
Submitter: Son Nguyen (<email address hidden>)
Branch: master

commit 3743dcf68d1058f647081cf5d29662181978fd01
Author: Robert Lyon <email address hidden>
Date: Thu Nov 20 09:04:00 2014 +1300

Always specify what base type we want returned from parseInt()

Bug 1394330

In most places in mahara we specify that we want base 10 number
returned (or base 16 in case of a hexidecimal css colour)

But there are a few places where we don't specify the radix at all

It's best practice to always include the radix because for older
browsers it interprets leading 0 as octal by default.

Also makes it clearer to developers what type of number is expected to
be retrieved from the string.

Change-Id: Iaecc85cbed875f85b313188c4e96cc1b77c77b31
Signed-off-by: Robert Lyon <email address hidden>

Robert Lyon (robertl-9) on 2014-11-24
Changed in mahara:
status: In Progress → Fix Committed
Mahara Bot (dev-mahara) wrote :

Patch for "1.9_STABLE" branch: https://reviews.mahara.org/4027

Mahara Bot (dev-mahara) wrote :

Patch for "1.10_STABLE" branch: https://reviews.mahara.org/4028

Reviewed: https://reviews.mahara.org/4026
Committed: http://gitorious.org/mahara/mahara/commit/f1b597e19838d9857ba676d7f228d2f075b09193
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.8_STABLE

commit f1b597e19838d9857ba676d7f228d2f075b09193
Author: Robert Lyon <email address hidden>
Date: Thu Nov 20 09:04:00 2014 +1300

Always specify what base type we want returned from parseInt()

Bug 1394330

In most places in mahara we specify that we want base 10 number
returned (or base 16 in case of a hexidecimal css colour)

But there are a few places where we don't specify the radix at all

It's best practice to always include the radix because for older
browsers it interprets leading 0 as octal by default.

Also makes it clearer to developers what type of number is expected to
be retrieved from the string.

Change-Id: Iaecc85cbed875f85b313188c4e96cc1b77c77b31
Signed-off-by: Robert Lyon <email address hidden>

Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/4027
Committed: http://gitorious.org/mahara/mahara/commit/ab89e765505118d92a43fd4a41044118b528d84e
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.9_STABLE

commit ab89e765505118d92a43fd4a41044118b528d84e
Author: Robert Lyon <email address hidden>
Date: Thu Nov 20 09:04:00 2014 +1300

Always specify what base type we want returned from parseInt()

Bug 1394330

In most places in mahara we specify that we want base 10 number
returned (or base 16 in case of a hexidecimal css colour)

But there are a few places where we don't specify the radix at all

It's best practice to always include the radix because for older
browsers it interprets leading 0 as octal by default.

Also makes it clearer to developers what type of number is expected to
be retrieved from the string.

Change-Id: Iaecc85cbed875f85b313188c4e96cc1b77c77b31
Signed-off-by: Robert Lyon <email address hidden>

Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/4028
Committed: http://gitorious.org/mahara/mahara/commit/d98f2ada6289d364c628f8910cc4713be2282857
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.10_STABLE

commit d98f2ada6289d364c628f8910cc4713be2282857
Author: Robert Lyon <email address hidden>
Date: Thu Nov 20 09:04:00 2014 +1300

Always specify what base type we want returned from parseInt()

Bug 1394330

In most places in mahara we specify that we want base 10 number
returned (or base 16 in case of a hexidecimal css colour)

But there are a few places where we don't specify the radix at all

It's best practice to always include the radix because for older
browsers it interprets leading 0 as octal by default.

Also makes it clearer to developers what type of number is expected to
be retrieved from the string.

Change-Id: Iaecc85cbed875f85b313188c4e96cc1b77c77b31
Signed-off-by: Robert Lyon <email address hidden>

Robert Lyon (robertl-9) on 2015-04-17
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers