Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.17k stars 730 forks source link

Error in File Reference in file path containing `%20` #9466

Closed Andrew-D-Wilson closed 10 months ago

Andrew-D-Wilson commented 1 year ago

Bicep version v0.13.1

Describe the bug When working in a Git repository that's name contains spaces, the bicep 'module' then errors.

Such that if the cloned folder is demo%20repo, the error is as follows: An error occurred reading file. Could not find a part of the path 'c:\src\demo repo\Bicep-Templates\storage-account.bicep'.

This also prevents building into ARM.

To Reproduce Steps to reproduce the behavior:

  1. Create a folder with %20 in the name.
  2. Create a Bicep template with a module reference to another template.
  3. Error warning appears and inability to build.
chielboogaard commented 1 year ago

I got the same issue, if there is any solution hope it lands here

anthony-c-martin commented 1 year ago

Possibly related to #8383

anthony-c-martin commented 1 year ago

@Andrew-D-Wilson when you are building Bicep, are you using the VSCode "Build ARM Template" command, or are you using Azure CLI or Bicep CLI?

Andrew-D-Wilson commented 1 year ago

@anthony-c-martin , I can build the ARM templates with Bicep CLI I can Build the ARM templates with Azure CLI

I cant build with VSCode "Build ARM Templates" The file is also indicated as having errors when opened in VSCode: image

anthony-c-martin commented 1 year ago

To me this looks like a bug in OmniSharp's DocumentUri.ToUri(), which we use to convert from the LSP URI to a .NET URI:

image

If we have a file path containing %20, the URI is correctly presented to the language server by VSCode containing escaped %2520. This appears to be correctly represented in documentUri (see screenshot). When we call documentUri.ToUri(), this appears to remove the escaping and instead represents the Uri with %20 - meaning this is considered to be a space instead of a legitimate %20 when the path is converted into a file system path using uri.LocalPath.

anthony-c-martin commented 1 year ago

I added a test to repro this issue: https://github.com/Azure/bicep/blob/cccaa80002cd8dfaadee0f136b297a9f8032e6d4/src/Bicep.LangServer.IntegrationTests/TextDocumentSyncTests.cs#L109

riosengineer commented 1 year ago

Is there any ETA on when this may be fixed please?

segraef commented 12 months ago

same issue here by the way, once the repo name or the local folder contains a %20 Bicep is not able to reference the child module, just tested on Mac and Linux

in folder with %20

image

in folder without %20

image image

shenglol commented 11 months ago

I did some investigation, and this does seem to be an upstream bug in the Omnisharp LSP package: https://github.com/OmniSharp/csharp-language-server-protocol/issues/1005. I'll be submitting a temp fix to the Bicep repo soon before the upstream bug is acknowledged and fixed.