diff --git a/CHANGELOG.md b/CHANGELOG.md index ad62ed6280ae869bec7379848edf57c2ea2b2562..a044b74c21c86e4cf81272a935db49920d337107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### 4.1.0-beta.10 + Fix issue #502 The end-to-end tests fails on Chrome 61 ++ Fix issue #505 Pasting values in a `readOnly` element should not be possible ### 4.1.0-beta.9 + Fix issue #498 The `twoScaled` choice for the `digitalGroupSpacing` option cannot be validated diff --git a/package.json b/package.json index b24c1e6037e89bf456512eeb35e356c995991fb0..d8ac50cd67efac0bc0207804e60a9a7680a6cb67 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "autonumeric", - "version": "4.1.0-beta.9", + "version": "4.1.0-beta.10", "description": "autoNumeric is a standalone Javascript library that provides live *as-you-type* formatting for international numbers and currencies. It supports most international numeric formats and currencies including those used in Europe, Asia, and North and South America.", "main": "dist/autoNumeric.js", "readmeFilename": "README.md", diff --git a/src/AutoNumeric.js b/src/AutoNumeric.js index d6a5c370b67bb8c515306672e4e568ae2ce607a2..8605e550fe657506267c6039f7852b44a5e5e45e 100644 --- a/src/AutoNumeric.js +++ b/src/AutoNumeric.js @@ -5978,6 +5978,11 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o // The event is prevented by default, since otherwise the user would be able to paste invalid characters into the input e.preventDefault(); + if (this.settings.readOnly) { + // Do not allow pasting in a readonly element (fix issue #505) + return; + } + let rawPastedText; if (window.clipboardData && window.clipboardData.getData) { // Special case for the obsolete and non-standard IE browsers 10 and 11 diff --git a/test/e2e/specs/autoNumeric.e2e.spec.js b/test/e2e/specs/autoNumeric.e2e.spec.js index 459fef9b7363666eb070f86cb13c92635de1b867..fce08e15c3c37fd95a0aeca54a1e6256509c70d3 100644 --- a/test/e2e/specs/autoNumeric.e2e.spec.js +++ b/test/e2e/specs/autoNumeric.e2e.spec.js @@ -3708,4 +3708,24 @@ describe('Pasting', () => { browser.keys(['Control', 'a', 'v', 'Control']); expect(browser.getValue(selectors.issue387inputCancellable)).toEqual('$220,242.76'); }); + + it('should not be possible to paste an valid number in a readOnly element', () => { + expect(browser.getValue(selectors.readOnlyElement)).toEqual('42.42'); + + const inputClassic = $(selectors.inputClassic); + inputClassic.click(); + // Clear the input content + browser.keys(['Control', 'a', 'Control', 'Backspace']); + browser.keys('12345.67'); + expect(browser.getValue(selectors.inputClassic)).toEqual('12345.67'); + + // Copy + browser.keys(['Control', 'a', 'c', 'Control']); + + // Paste + $(selectors.readOnlyElement).click(); + browser.keys(['Home', 'ArrowRight', 'Shift', 'ArrowRight', 'ArrowRight', 'Shift']); + browser.keys(['Control', 'a', 'v', 'Control']); + expect(browser.getValue(selectors.readOnlyElement)).toEqual('42.42'); // No changes! + }); });