Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295783

Client side file extension validation for managed files fails on Internet Explorer 11

$
0
0

On Drupal 7 and 8 when selecting a file with an invalid file extension using the managed file field, javascript's onchange event callback Drupal.file.validateExtension() is called. This callback:

  1. removes error messages that were possible inserted into the DOM earlier,
  2. detects a wrong file extension,
  3. inserts a new error message into the DOM,
  4. sets the field's value to an empty string and
  5. stops propagating the event.

On Internet Explorer 11 programmatically resetting the value using this.value = ''; fires the onchange event again. This time:

  1. the previous error message is being removed (the user will never know what went wrong),
  2. the field has no value, so no wrong file extension is being detected and
  3. the event propagating is not being stopped (other onchange callbacks like D8's Drupal.file.triggerUploadButton will get fired).

This can be tested using http://jsfiddle.net/lmeurs/2rEzF/ or with Drupal using http://simplytest.me/project/drupal: set permissions for anonymous users to create articles so you can add articles from different browsers (ie. using http://browserstack.com) and test with the image field.

Sidenote: On < IE11 it seems not possible to programmatically reset the field's value.

Possible solution

The best fix I can think of is to immediately exit Drupal.file.validateExtension() when the field has no value. Use something like:

if (!this.value) return;


Viewing all articles
Browse latest Browse all 295783


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>