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 therelativeUri
. IfrelativeUri
is an absolute URI (containing a scheme, host name, and optionally a port number), the Uri instance is created using onlyrelativeUri
.
If the
baseUri
has relative parts (like/api
), then the relative part must be terminated with a slash, (like/api/
), if the relative part ofbaseUri
is to be preserved in the constructed Uri.
Additionally, if the
relativeUri
begins with a slash, then it will replace any relative part of thebaseUri
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