Custom Rule with regex

Hello,
I see in the documentation that we could make xpath rules
but I don’t have the impression that we can make a regex, I saw that it has a field with Ant-style matching patterns, but I don’t know if it corresponds to a regex expression
in my case , I would like to check the syntax of the calendar name with a regex

 <Calendar name="**c_standard**" year="2019" publicHolidays="1" specificDays="0" firstInWeek="0"

In the Custom Rule form
Field Expression

//Calendars/Calendar

Field FilePattern
nothing yet

I tried to add “match” in the xpath expression but it doesn’t work
Can you help me
Thanks.

  • SonarQube 8.4.2

I just tested

// Calendars / Calendar [fn: matches (@name, '^ [a-zA-Z0-9] * _ [a-zA-Z0-9] * $')] 

I have the error message

java.lang.IllegalStateException: Failed to compile XPath expression based on user-provided parameter [//Calendars/Calendar[fn:matches(@name,'^[a-zA-Z0-9]*_[a-zA-Z0-9]*$')]]

the doc that I followed
https://www.w3.org/TR/xpath-functions-31/#func-matches
can you help me ?
Thanks

hello !
no one has dealt with this type of case ?
thanks

Hello @Jerome_LEBAS,

Unfortunately, you won’t be able to write such a pattern with our XPath rule, as your rule is based on XPath 3.1 syntax.

The XML analyzer XPath rule we are providing is only able to process XPath 1.0 syntax. We tried in the past to provide support of XPath 2.x and 3.x, without success. See SONARXML-68 for further details.

Cheers,
Michael

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