Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48869

CsharpNamespaceDetector does not recognize "namespace" preceded by UTF-8 BOM

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: analysis-core-plugin
    • Labels:
    • Environment:
      Jenkins 2.89.2
      Static Analysis Utilities 1.93
      Warnings Plug-in 4.64
      Windows
    • Similar Issues:

      Description

      If there are some compiler warnings about a C# source file that is encoded in UTF-8 and starts with a Byte Order Mark, and the BOM is immediately followed by "namespace " and the name of the namespace, then the Warnings Plug-in does not recognize the namespace declaration and instead displays the relative directory name.

      If I insert CRLF between the BOM and "namespace", then the Warnings Plug-in correctly displays the name of the namespace. Likewise, the namespace detector works OK if there is a comment with copyright notices at the top of the file.

      Because I cannot find any namespace detection code in the Warnings Plug-in itself, I believe the problem is in the hudson.plugins.analysis.util.CsharpNamespaceDetector class, defined in Static Analysis Utilities aka analysis-core. It decodes the file as UTF-8 and then checks each line against the regexp "^namespace .*$" until it finds a match. Perhaps this can be changed to allow "\uFEFF" at the start of the line, or more generally whitespace.

        Attachments

          Activity

          kon Kalle Niemitalo created issue -
          kon Kalle Niemitalo made changes -
          Field Original Value New Value
          Attachment JENKINS-48869.test-case.zip [ 41088 ]
          kon Kalle Niemitalo made changes -
          Description If there are some compiler warnings about a C# source file that is encoded in UTF-8 and starts with a Byte Order Mark, and the BOM is immediately followed by "namespace " and the name of the namespace, then the Warnings Plug-in does not recognize the namespace declaration and instead displays the relative file name.

          If I insert CRLF between the BOM and "namespace", then the Warnings Plug-in correctly displays the name of the namespace. Likewise, the namespace detector works OK if there is a comment with copyright notices at the top of the file.

          Because I cannot find any namespace detection code in the Warnings Plug-in itself, I believe the problem is in the hudson.plugins.analysis.util.CsharpNamespaceDetector class, defined in Static Analysis Utilities aka analysis-core. It decodes the file as UTF-8 and then checks each line against the regexp "^namespace .*$" until it finds a match. Perhaps this can be changed to allow "\uFEFF" at the start of the line, or more generally whitespace.
          If there are some compiler warnings about a C# source file that is encoded in UTF-8 and starts with a Byte Order Mark, and the BOM is immediately followed by "namespace " and the name of the namespace, then the Warnings Plug-in does not recognize the namespace declaration and instead displays the relative directory name.

          If I insert CRLF between the BOM and "namespace", then the Warnings Plug-in correctly displays the name of the namespace. Likewise, the namespace detector works OK if there is a comment with copyright notices at the top of the file.

          Because I cannot find any namespace detection code in the Warnings Plug-in itself, I believe the problem is in the hudson.plugins.analysis.util.CsharpNamespaceDetector class, defined in Static Analysis Utilities aka analysis-core. It decodes the file as UTF-8 and then checks each line against the regexp "^namespace .*$" until it finds a match. Perhaps this can be changed to allow "\uFEFF" at the start of the line, or more generally whitespace.
          drulli Ulli Hafner made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]

            People

            • Assignee:
              drulli Ulli Hafner
              Reporter:
              kon Kalle Niemitalo
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: