Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

File encoding mismatch between SonarQube and sonar-delphi APIs #136

Closed
2 tasks done
zaneduffield opened this issue Dec 13, 2023 · 1 comment · Fixed by #148
Closed
2 tasks done

File encoding mismatch between SonarQube and sonar-delphi APIs #136

zaneduffield opened this issue Dec 13, 2023 · 1 comment · Fixed by #148
Assignees
Labels
bug Something isn't working

Comments

@zaneduffield
Copy link
Collaborator

zaneduffield commented Dec 13, 2023

Prerequisites

  • This bug is in SonarDelphi, not SonarQube or my Delphi code.
  • This bug has not already been reported.

SonarDelphi version

1.0.0

SonarQube version

No response

Issue description

Currently, sonar-delphi simply uses the filesystem-level encoding provided by the sonar-scanner engine.
However, the sonar-scanner engine actually determines file encodings at the file level, using heuristics:

https://github.com/SonarSource/sonarqube/blob/f50873318397d4bf7ba6a5c2b194dfa02492bdae/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/MetadataGenerator.java#L53
https://github.com/SonarSource/sonarqube/blob/f50873318397d4bf7ba6a5c2b194dfa02492bdae/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/ByteCharsetDetector.java#L48

This encoding is then saved on the InputFile which can be accessed via InputFile::charset

This can lead to errors in file offsets, when sonar-delphi is decoding the file using a different charset than the sonar-scanner engine.

Steps to reproduce

Scan the following (utf-8 encoded) source file

program LineOffsetBug;

begin
                           // LEcranPrincipal doit être la 1ère vraie form créée pour être la main form fenêtre principale
end.

with sonar.sourceEncoding set to windows-1252.

Minimal Delphi code exhibiting the issue

No response

@zaneduffield zaneduffield added bug Something isn't working triage This needs to be triaged by a maintainer labels Dec 13, 2023
@Cirras Cirras removed the triage This needs to be triaged by a maintainer label Dec 13, 2023
@Cirras
Copy link
Collaborator

Cirras commented Dec 21, 2023

In addition, SonarDelphi never discards the user's provided encoding - even when there's a BOM clearly indicating the encoding of the file.
Another detail that's inconsistent with sonar-scanner-engine and should be changed.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
2 participants