Fix failure to open paths ending in a slash.

Redmine #3905.
Do not attempt to expand functions in the middle of an iteration
Add warning when using known problematic variables in package promise.

Discovered while writing acceptance tests for package promises, and
very hard to understand what's going on unless you get this warning.
Fix incorrect return value for empty string in safe_open.
Tiny optimization in safe_open.

We already know that next_component is neither null nor empty in the
second branch, because of 7f137f0ad5.
Merge pull request #1243 from kacfengine/safe_open_fixes

[Redmine #3905] Safe open fixes
Merge pull request #1246 from kacfengine/packages_variables_warning

Add warning when using known problematic variables in package promise.