function decodePath(path, html5Mode) {
  var segments = path.split('/'),
      i = segments.length;

  while (i--) {
    segments[i] = decodeURIComponent(segments[i]);
    if (html5Mode) {
      // encode forward slashes to prevent them from being mistaken for path separators
      segments[i] = segments[i].replace(/\//g, '%2F');
    }
  }

  return segments.join('/');
}
@ngdoc service
@name $sceDelegate
@kind function

@description

`$sceDelegate` is a service that is used by the `$sce` service to provide {@link ng.$sce Strict
Contextual Escaping (SCE)} services to AngularJS.

For an overview of this service and the functionnality it provides in AngularJS, see the main
page for {@link ng.$sce SCE}. The current page is targeted for developers who need to alter how
SCE works in their application, which shouldn't be needed in most cases.

<div class="alert alert-danger">
AngularJS strongly relies on contextual escaping for the security of bindings: disabling or
modifying this might cause cross site scripting (XSS) vulnerabilities. For libraries owners,
changes to this service will also influence users, so be extra careful and document your changes.
</div>

Typically, you would configure or override the {@link ng.$sceDelegate $sceDelegate} instead of
the `$sce` service to customize the way Strict Contextual Escaping works in AngularJS.  This is
because, while the `$sce` provides numerous shorthand methods, etc., you really only need to
override 3 core functions (`trustAs`, `getTrusted` and `valueOf`) to replace the way things
work because `$sce` delegates to `$sceDelegate` for these operations.

Refer {@link ng.$sceDelegateProvider $sceDelegateProvider} to configure this service.

The default instance of `$sceDelegate` should work out of the box with little pain.  While you
can override it completely to change the behavior of `$sce`, the common case would
involve configuring the {@link ng.$sceDelegateProvider $sceDelegateProvider} instead by setting
your own whitelists and blacklists for trusting URLs used for loading AngularJS resources such as
templates.  Refer {@link ng.$sceDelegateProvider#resourceUrlWhitelist
$sceDelegateProvider.resourceUrlWhitelist} and {@link
ng.$sceDelegateProvider#resourceUrlBlacklist $sceDelegateProvider.resourceUrlBlacklist}