OpenBeta / sandbag

JS utilities for working with climbing grades
MIT License
24 stars 17 forks source link

Slash grades are buggy #174

Open Agilulfo opened 1 month ago

Agilulfo commented 1 month ago

While working at the Polish scale implementation I've noticed that there is a bug in the validation of the slash grades.

The implementation of the french scale is affected but also other scales use the same logic.

In the case of the french scale It looks like a regex checks that the syntax of the grade is correct but not the semantic. in particular "5a/6a" is considered a valid grade. I don't think is intentional also because the score range returned in this case is the same that 5a/5a+ would return.

in the definition of the function get score there is an assumption that the part after the slash is related to the first part. however the regexp used in the initial validation alone cannot validate the relation between the grades.

A solution could be to extend the validation to also check that in case of / grades the relation between them is valid.

It is worth in my opinion to check also the remaining scales to make sure the same logic has not been copy-pasted in there too and eventually consider reusable / grade validation logic.

here you will find a commit where I've added a test that is failing