Skip to main content

Search and Top Navigation

#8462 closed bug (notabug)

Opened July 26, 2012 04:23PM UTC

Closed July 26, 2012 04:26PM UTC

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:


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
format, if the value
was set when the
method was called, it would modify the input value to be

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.

Attachments (0)
Change History (1)

Changed July 26, 2012 04:26PM UTC by scottgonzalez comment:1

resolution: → invalid
status: newclosed

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