Enterprise: Locale: cultureInHead assumes all script tags have a src attribute

Created on 18 Nov 2019  路  2Comments  路  Source: infor-design/enterprise

Describe the bug
When the document contains a script tag (in any location) without a src, the cultureInHead method fails with a null reference exception.

To Reproduce
Steps to reproduce the behavior:
include a link to cultures/en-US.js, which calls Soho.Locale.addCulture('en-US', ...)
Now call Locale.set("en-US")
This will call cultureInHead, which will fail if any script tags are missing a src attribute.

Here is the current source code which shows that every script tag is examined and the first tag it encounters without a src attribute will create a reference exception:

  cultureInHead() {
    const scripts = document.getElementsByTagName('script');
    const partialPath = 'cultures';

    for (let i = 0; i < scripts.length; i++) {
      const src = scripts[i].src;

      if (src.indexOf(partialPath) > -1) {
        return true;
      }
    }

    return false;
  },

The proposed fix would exit the method as soon as the first match was found and would guard against src being a non-string (src && src.indexOf).

[2] type

All 2 comments

Ok i get it now. Thats strange since our demo app has a few of these. If you wanted to do a PR feel free.

I tried reproducing by created