Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new feature: support hex number like 0xfff #1306 #2798

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions core/field_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ Blockly.FieldNumber.prototype.doClassValidation_ = function(opt_newValue) {
newValue = newValue.replace(/O/ig, '0');
// Strip out thousands separators.
newValue = newValue.replace(/,/g, '');

// Clean up number.
var n = Number(newValue || 0);
var hex = newValue.match(/^0xX+$/g);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do what you think it does. This match is looking for start of the line followed by '0x' followed by 1 or more 'X' characters followed by the end of the line. So it would match '0xXXXXXXXXXXXX' but not '0xabc'.

var n = hex ? parseInt(newValue, 16) : Number(newValue || 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also isn't necessary, Number('0xabc') and parseInt('0xabc', 16) both return the same value, 2748. Converting a 3 letter hex color to a 6 letter number is a bit trickier than this.

if (isNaN(n)) {
// Invalid number.
return null;
Expand Down