Skip to content

GetLocalPath returns invalid path when a provider has empty webPath (StrCompLeft matches empty strings) #38

@0scarius

Description

@0scarius

Description

GetLocalPath produces an invalid local path containing the full SharePoint URL when a OneDrive Business provider's ClientPolicy*.ini file lacks a DavUrlNamespace tag (or the file is missing/unreadable), resulting in an empty .webPath for that provider.

This causes Dir() to raise Run-time error '52': Bad file name or number.

Steps to reproduce

  1. Have a SharePoint-synced workbook where the corresponding ClientPolicy.ini (or ClientPolicy_*.ini) does not contain a DavUrlNamespace entry
  2. Call GetLocalPath(ActiveWorkbook.Path) where the path is a SharePoint URL

Expected result

A valid local path like:

C:\Users\JDoe\OneDrive - Contoso\Shared Documents\Projects\2025\Data

Actual result

C:\Users\JDoe\OneDrive - Contoso\https:\contoso.sharepoint.com\sites\TeamSite\Shared Documents\Projects\2025\Data

Root cause

Two issues:

1. StrCompLeft returns 0 (match) when s2 is empty.

When .webPath is "", the comparison StrCompLeft(odWebPath, "", vbTextCompare) evaluates as:

StrComp(Left$(odWebPath, Len("")), "") → StrComp("", "") → 0  ' Match!

This means a provider with an empty webPath will match any URL input.

2. AddBusinessProviders does not validate tempURL before adding.

The canAdd guard only checks LenB(tempMount) > 0 but not LenB(tempURL) > 0, so providers with empty web paths are added to the cache.

Suggested fix

In StrCompLeft, add an early exit when either string is empty:

Private Function StrCompLeft(ByRef s1 As String _
                           , ByRef s2 As String _
                           , ByVal compareMethod As VbCompareMethod) As Long
    If Len(s1) = 0 Or Len(s2) = 0 Then
        StrCompLeft = -CLng(Len(s1) = 0) + CLng(Len(s2) = 0)
        Exit Function
    End If
    If Len(s1) > Len(s2) Then
        StrCompLeft = StrComp(Left$(s1, Len(s2)), s2, compareMethod)
    Else
        StrCompLeft = StrComp(s1, Left$(s2, Len(s1)), compareMethod)
    End If
End Function

In AddBusinessProviders, change:

If canAdd Then

to:

If canAdd And LenB(tempURL) > 0 Then

Environment

  • Windows 11, Excel (Desktop)
  • OneDrive for Business syncing SharePoint libraries
  • ActiveWorkbook.Path returns a https:// SharePoint URL

Note: This bug report and suggested fix were generated with AI assistance (Claude).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions