diff -u b/core/modules/file/file.es6.js b/core/modules/file/file.es6.js --- b/core/modules/file/file.es6.js +++ b/core/modules/file/file.es6.js @@ -19,53 +19,23 @@ * Detaches validation for file extensions. */ Drupal.behaviors.fileValidateAutoAttach = { -<<<<<<< HEAD - attach(context, settings) { + attach: function (context) { const $context = $(context); let elements; - function initFileValidation(selector) { - $context.find(selector) - .once('fileValidate') - .on('change.fileValidate', { extensions: elements[selector] }, Drupal.file.validateExtension); - } - - if (settings.file && settings.file.elements) { - elements = settings.file.elements; - Object.keys(elements).forEach(initFileValidation); - } - }, - detach(context, settings, trigger) { - const $context = $(context); - let elements; -======= - attach: function (context) { - var $context = $(context); - var elements; - $context.find('[data-drupal-validate-extensions]') .once('fileValidate') .on('change.fileValidate', Drupal.file.validateExtension); }, - detach: function (context, settings, trigger) { - var $context = $(context); ->>>>>>> Applying patch from issue 2235977 comment 114 + detach(context, settings, trigger) { + const $context = $(context); if (trigger === 'unload') { $context.find('[data-drupal-validate-extensions]') .removeOnce('fileValidate') .off('change.fileValidate', Drupal.file.validateExtension); } -<<<<<<< HEAD - - if (trigger === 'unload' && settings.file && settings.file.elements) { - elements = settings.file.elements; - Object.keys(elements).forEach(removeFileValidation); - } - }, -======= } ->>>>>>> Applying patch from issue 2235977 comment 114 }; /** @@ -152,13 +122,6 @@ $('.file-upload-js-error').remove(); // Add client side validation for the input[type=file]. -<<<<<<< HEAD - const extensionPattern = event.data.extensions.replace(/,\s*/g, '|'); - if (extensionPattern.length > 1 && this.value.length > 0) { - const acceptableMatch = new RegExp(`\\.(${extensionPattern})$`, 'gi'); - if (!acceptableMatch.test(this.value)) { - const error = Drupal.t('The selected file %filename cannot be uploaded. Only files with the following extensions are allowed: %extensions.', { -======= var validExtensions = JSON.parse(event.target.getAttribute('data-drupal-validate-extensions')); if (validExtensions.length > 1 && event.target.value.length > 0) { var acceptableMatch = new RegExp('\\.(' + validExtensions.join('|') + ')$', 'i'); @@ -170,7 +133,6 @@ for (var i = 0; i < testSubjects.length; i++) { var testSubject = testSubjects[i]; if (!acceptableMatch.test(testSubject.name)) { ->>>>>>> Applying patch from issue 2235977 comment 114 // According to the specifications of HTML5, a file upload control // should not reveal the real local path to the file that a user // has selected. Some web browsers implement this restriction by @@ -178,18 +140,11 @@ // confusion by leaving the user thinking perhaps Drupal could not // find the file because it messed up the file path. To avoid this // confusion, therefore, we strip out the bogus fakepath string. -<<<<<<< HEAD - '%filename': this.value.replace('C:\\fakepath\\', ''), - '%extensions': extensionPattern.replace(/\|/g, ', '), - }); - $(this).closest('div.js-form-managed-file').prepend(`
`); -======= invalidFiles.push(testSubject.name.replace('C:\\fakepath\\', '')); } } if (invalidFiles.length) { $(this).closest('div.js-form-managed-file').prepend(Drupal.theme('fileValidationError', invalidFiles, validExtensions)); ->>>>>>> Applying patch from issue 2235977 comment 114 this.value = ''; // Cancel all other change event handlers. event.stopImmediatePropagation(); @@ -289,9 +244,6 @@ window.open(this.href, 'filePreview', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=500,height=550'); }, }; -<<<<<<< HEAD -}(jQuery, Drupal)); -======= /** * Error message of file validation. @@ -326,2 +278 @@ -})(jQuery, Drupal); ->>>>>>> Applying patch from issue 2235977 comment 114 +}(jQuery, Drupal)); diff -u b/core/modules/file/file.js b/core/modules/file/file.js --- b/core/modules/file/file.js +++ b/core/modules/file/file.js @@ -15,14 +15,6 @@ }, detach: function detach(context, settings, trigger) { var $context = $(context); -<<<<<<< HEAD - var elements = void 0; - - function removeFileValidation(selector) { - $context.find(selector).removeOnce('fileValidate').off('change.fileValidate', Drupal.file.validateExtension); - } -======= ->>>>>>> Applying patch from issue 2235977 comment 114 if (trigger === 'unload') { $context.find('[data-drupal-validate-extensions]').removeOnce('fileValidate').off('change.fileValidate', Drupal.file.validateExtension); @@ -157 +149 @@ -})(jQuery, Drupal); \ No newline at end of file +})(jQuery, Drupal);