fixes ISSUE #1317

Couldn't find an existing testing infrastructure for javascript to write tests for this patch, but I'm using this patch in my apps.