Links should not directly target image

I had html with direct links

<a href="../somedir/images/foo.jpg" >pic</a>

but I got lots of warnings about the issue listed in topic.
so I created a php page, with parameters,
<a href="bwpages.php?lrgdir=peace&lrgimg=peaceLifeMed.jpg">large version</a>
but you still see it as a direct link and report the issue;
Links should not directly target image
I think if you see php in the anchor href, it can be assumed to not be a direct link.

html page similar to this:

<p>Vancouver Peace March, 1986, Peace recruitment</p>
<p>photo &copy;Graeme Elliott</p>
<a href="bwpages.php?lrgdir=peace&lrgimg=peaceLifeMed.jpg">large version</a>

sonarqube reports the followin issue for this ^ line:
Change this link to not directly target an image.
*** last month**
*** L26**
*** Code Smell**
*** Major**
*** Open**
*** Not assigned**
*** 15min effort * accessibility, user-experience**


hello @graeme_sonarqb,

this check is quite naive, it only detects image by testing that url ends with some known image file extension. You could also simply swap the order of parameters in the url to get rid of the issue.
This rule is intended for standard html pages, I think that when you generate the links dynamically, it will be easier to just disable the rule for the project, if you don’t find it usefull.

the feature is very useful, when the result is correct. I think the implementation could be fixed fairly easily. If there is a ? mark in the url, assume a parmeter list, and not report the issue. That too is naive, but less naive that the current implementation.
I am going to try switching the parameter order.
I have been running sonarqube over my website, which has html and code back 15 years, when I did not know better. It has been great in letting me clean up the legacy mess I wrote.

<a href="bwpages.php?lrgdir=peace&lrgimg=peaceLifeMed.jpg">large version</a>

I switched the parameter order, so &lrgidr=xxxx is at the end of the anchor and it works fine. Like this:
<a href="bwpages.php?lrgimg=peaceLifeMed.jpg&lrgdir=peace">large version</a>