swift:S1451: False Positive with Regex

versions
Sonar Version 6.7.3 (build 38370)
SonarQube Scanner 3.2.0.1227
Swift Plugin 4.1

Sample
We have a single line header with the copyright, which matches this regex:

[\+\*!,\.-a-zA-Z0-9_\s&\w]* Copyright (©|\(C\)) \d{4} COMPANYNAME [&a-zA-Z0-9_\s,\.]*

Applied to this header gives an false positive, since it should match the regex:
// Copyright © 2017 COMPANYNAME All rights reserved.

Example match: https://regex101.com/r/egc2qM/3

When we add an empty line before the header it works. Also if we add another comment line with // it works. However it stops working this line is the first in the file.

1 Like

Thank you, Simon, for reporting to us this FP. I’ve opened SONARSWIFT-423 to track it.

I expect you meant 4.1 (the latest released version).

Cheers,
Andrei

Sure, 4.1, thanks! I changed it.

1 Like

HI,
I have the same problem in Java. My copyright is matching the regex but I have issues in all files.

/*

  • Copyright © 2001-2019 Group TOTO.
  • 17 rue Soyer, 92523 Neuilly Cedex, France.
  • All rights reserved.
  • This software is the confidential and proprietary information
  • of Group TOTO(“Confidential Information”). You shall not
  • disclose such Confidential Information and shall use it only
  • in accordance with the terms of the license agreement you
  • entered into with Group TOTO.
    */

/* {0,1}\n\s* Copyright (c) 2001-20[0-9]{2} Group TOTO. {0,1}\n\s* 17 rue Soyer, 92523 Neuilly Cedex, France. {0,1}\n\s* All rights reserved. {0,1}\n\s* {0,1}\n\s* This software is the confidential and proprietary information {0,1}\n\s* of Group TOTO(“Confidential Information”). You shall not {0,1}\n\s* disclose such Confidential Information and shall use it only {0,1}\n\s* in accordance with the terms of the license agreement you {0,1}\n\s* entered into with Group TOTO. {0,1}\n\s*/\n{0,1}

Any solution ?