-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes undefined offset by adding an isset test #1103
Conversation
Kudos, SonarCloud Quality Gate passed!
|
Codecov Report
@@ Coverage Diff @@
## master #1103 +/- ##
=========================================
Coverage 60.30% 60.30%
Complexity 1592 1592
=========================================
Files 32 32
Lines 4431 4431
=========================================
Hits 2672 2672
Misses 1759 1759 Continue to review full report at Codecov.
|
The situation where this can happen is when a vocabulary has been configured to have a certain language, but there are actually no prefLabels with that language tag. The code in WebController tries to find the first alphabet letter for which prefLabels exist, but when there are no such prefLabels, the list is empty. This is basically a configuration error but these things happen, even in production as you've noticed by checking the logs. I think we need a unit test to check for this situation. The suggested fix may be OK, I need to double-check. The sane result in this not-so-sane situation would be to show an empty list of alphabet letters as well as an empty alphabetical listing of concepts. |
SonarCloud Quality Gate failed.
|
I will merge this assuming the Travis CI tests pass. The SonarCloud complaint is irrelevant, it complains about identical blocks in unit tests (true, but harmless). |
Can't wait for Travis, but the tests pass locally, so merging this. |
Whilst checking php error log for a Skosmos instance I noticed that the line 467 below
Skosmos/controller/WebController.php
Lines 443 to 473 in 254c2c6
Undefined offset: 0
PHP Notice.By following the code it calls it seems like the
NULL
value is then passed here:Skosmos/model/sparql/GenericSparql.php
Lines 1187 to 1216 in 254c2c6
where at line 1207 it is again (luckily) changed back to an empty string. This will, however, cause a filter clause that has a STRSTARTS() with an empty argument, which is unnecessary and will always evaluate to True.
Whilst this PR fixes the PHP notice, it won't change the behavior (i.e., the query as it is, now). I wonder if it would be more appropriate to, in this case, change the letter value to "*", for which there is a special treatment (unlike for empty string). However, now that I look into that, it seems like the
STRSTARTS
part is unnecessary for the aforementioned "*" value.Additionally, I just noticed that this also affects the JenaTextSparql:
Skosmos/model/sparql/JenaTextSparql.php
Lines 102 to 171 in 254c2c6
Before merging it should be discussed whether something else should be done to both of these SPARQL parts, namely, if there should be a more special treatment for "*" and whether or not the letter value should be changed to that very same value.