Fix issue with SCRIPT_NAME handling and test to prevent regressions