Dotnet Sonar scanner 5.9.0 does not preserve relative part of sonar.host.url

SonarQube version: 8.9.10.61524
Dotnet Scanner version: 5.9.0

We recently upgraded dotnet sonar-scanner from 5.8.0 to 5.9.0 and discovered that the relative part of the host url is not preserved for all api calls. Our sonarcube installation is not available in the root folder, but in /sonarqube/ (www.example.com/sonarqube/).

This can be seen by running dotnet sonarscanner begin together with /d:sonar.verbose=true and /d:sonar.host.url=https://www.example.com/sonarqube/.
The following is then shown in the log:

15:36:07.202 Downloading from https://www.example.com/sonarqube/api/server/version
15:36:07.512 Checking validity of server license
15:36:07.513 Downloading from https://www.example.com/api/editions/is_valid_license
15:36:07.563 Unexpected character encountered while parsing value: <. Path ‘’, line 0, position 0.

As you can see, it uses the correct url for api/server/version, but not for api/editions/is_valid_license

Looking at the differences in GitHub - SonarSource/sonar-scanner-msbuild: SonarScanner for .NET 5.8.0 used GetUrl in src/SonarScanner.MSBuild.PreProcessor/SonarWebService.cs which was purely string based.
5.9.0 instead uses GetUri which is Uri based.

The remarks section in Uri Constructor (System) | Microsoft Learn has this interesting part:

This constructor creates a Uri instance by combining the baseUri and the relativeUri. If relativeUri is an absolute URI (containing a scheme, host name, and optionally a port number), the Uri instance is created using only relativeUri.

If the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like /api/), if the relative part of baseUri is to be preserved in the constructed Uri.

Additionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

All calls to GetUri starts with a leading /, except GetUri("api/server/version") which is why that url is working.

The same issue exists in master too.

Should I create a corresponding issue in Sign in to GitHub · GitHub and a PR that fixes this? The easiest fix would probably be to remove the leadind / from all calls to GetUri. Any other suggestions on how to fix it?

/Patrik

4 Likes

We’re also experiencing the same problems. It appears the refactor to using URI’s has caused this issue. See Refactor SonarWebService to use Uri (#1401) · SonarSource/sonar-scanner-msbuild@0890bd1 · GitHub

2 Likes

Hi Patrik, thanks for reporting this. We are working already to a fix and we plan to do a hotfix release today.

You can follow the progress here: Regression from switch to Uri from Url · Issue #1429 · SonarSource/sonar-scanner-msbuild · GitHub

Should I have reported this directly to the gitlab issues? When I was about to do that, it said: for bug reports visit IntelliJ Platform - Sonar Community

No, you did exactly what we recommend. Thanks again for reporting the problem.

1 Like

Hi @patrik_sevallius, I’m happy to let you know that we released a new version with the fix.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.