Opened 11 years ago

Closed 11 years ago

#8462 closed bug (notabug)

Mask: - _parseValue parses values outside the range of each parts buffer

Reported by: flamewave Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: git (not yet released)
Keywords: Cc:
Blocked by: Blocking:


The _parseValue method of the Mask widget was not properly parsing the values from the masking. If a buffer matched more than one part of the masked value, the last matching value would be used even if it was outside the start and end indexes of the buffer item.

For example, with the following mask: "__/__/____" with definition functions for parsing a date in the "MM/dd/yyyy" format, if the value "__/__/2012" was set when the _parseValue method was called, it would modify the input value to be "01/02/____".

I was able to fix this issue by changing the _parseValue method to the following:

_parseValue: function()
    var bufferPosition, bufferObject, character, valuePosition = 0, lastFilledPosition = -1, value = this.element.val(), bufferLength = this.buffer.length;

    // remove all current values from the buffer
    this._removeValues(0, bufferLength);

    // seek through the buffer pulling characters from the value
    for (bufferPosition = 0; bufferPosition < bufferLength; bufferPosition += bufferObject.length)
        bufferObject = this.buffer[bufferPosition];
        for (valuePosition = 0; valuePosition < bufferObject.length; valuePosition++)
            character = value.substr(bufferObject.start + valuePosition, bufferObject.length - valuePosition);
            if (bufferObject.literal)
                if (!this._validValue(bufferObject, character))
                    // when parsing a literal from a raw .val() if it doesn't match, assume that the literal is missing from the val()

            character = this._validValue(bufferObject, character);
            if (character)
                bufferObject.value = character;
                lastFilledPosition = bufferPosition + bufferObject.length - 1;

        // allow "default values" to be passed back from the buffer functions
        if (!bufferObject.value && (character = this._validValue(bufferObject, "")))
            bufferObject.value = character;

    return lastFilledPosition;

I am unable to include a test case because neither jsFiddle or jsbin allow you to include the git/mask version of jQuery UI.

Change History (1)

comment:1 Changed 11 years ago by Scott González

Resolution: invalid
Status: newclosed

Mask is not a supported plugin as it is not released.

Note: See TracTickets for help on using tickets.