Emanuil Rusev
Emanuil Rusev

Reputation: 35265

Is it reliable to use string comparison for comparing semantic version strings

It seems like comparing semantic version strings, like this, always outputs the correct result - if the version on the left is greater than the expression would be true:

'1.12.2' > '1.11.12'

Are there scenarios when it wouldn't?

Upvotes: 1

Views: 168

Answers (1)

user229044
user229044

Reputation: 239521

Are there scenarios when it wouldn't?

Yes, lots:

echo '1.12.2' > '1.101.12'; # true

You cannot compare version strings this way. You may have found some that work, but it's purely coincidence.

Upvotes: 3

Related Questions