docs: def clean_folder_path(path, expected=None):
      '''
      :param path: A folder path to sanitize and parse
      :type path: string
      :param expected: Whether a folder ("folder"), a data object ("entity"), or either (None) is expected
      :type expected: string or None
      :returns: *folderpath*, *name*
  
      Unescape and parse *path* as a folder path to possibly an entity
      name.  Consecutive unescaped forward slashes "/" are collapsed to
      a single forward slash.  If *expected* is "folder", *name* is
      always returned as None.  Otherwise, the string to the right of
      the last unescaped "/" is considered a possible data object name
      and returned as such.
  
      '''
      folders = split_unescaped('/', path)
  
      if len(folders) == 0:
          return '/', None
  
      if expected == 'folder' or folders[-1] == '.' or folders[-1] == '..' or get_last_pos_of_char('/', path) == len(path) - 1:
          entity_name = None
      else:
          entity_name = unescape_name_str(folders.pop())
  
      sanitized_folders = []
  
      for folder in folders:
          if folder == '.':
              pass
          elif folder == '..':
              if len(sanitized_folders) > 0:
                  sanitized_folders.pop()
          else:
              sanitized_folders.append(unescape_folder_str(folder))
  
      return ('/' + '/'.join(sanitized_folders)), entity_name