[SP-1637] - backport for PDI-13102

fix and test
test is provided in form of integration test
corresponding PR for master: https://github.com/pentaho/pentaho-kettle/pull/848

@mattyb149 @hudak @brosander @mattcasters would you mind to review/merge