Skip to content

String#toLowerCase fails to lower final sigma after a space or non-cased character #3063

Open

Description

@trackoor

Bug description

String#toLowerCase() lowers Greek Σ (U+03A3) at the end of a word to medial σ (U+03C3) instead of final ς (U+03C2) whenever a non-cased, non-case-ignorable character (such as a space or digit) appears earlier in the string within the lookbehind window.

Single-word "ΟΔΟΣ".toLowerCase() returns "οδος" as expected, but "Η ΟΔΟΣ".toLowerCase() returns "η οδοσ" instead of "η οδος", and "1 AΣ".toLowerCase() returns "1 aσ" instead of "1 aς". In JavaScript, Σ is lowered to ς whenever it is immediately preceded by a cased character (ignoring case-ignorable characters) and not followed by one.

In isFinalSigma, the backward loop sets found = true when it matches a preceding cased character, but is missing a break;, so it continues scanning backwards and returns false upon hitting an earlier space or other non-cased character.

Steps to reproduce

assert("ΟΔΟΣ".toLowerCase() == "οδος");     // passes
assert("Η ΟΔΟΣ".toLowerCase() == "η οδος"); // fails: returns "η οδοσ"
assert("1 AΣ".toLowerCase() == "1 aς");     // fails: returns "1 aσ"

Credit: https://ucsbplse.github.io/

AssemblyScript version

v0.28.20

Playground

https://www.assemblyscript.org/editor.html#IyFvcHRpbWl6ZT1zcGVlZCZydW50aW1lPWluY3JlbWVudGFsCi8vIGZpbmFsIHNpZ21hIFUrMDNDMiBleHBlY3RlZCBhZnRlciBhIGNhc2VkIGxldHRlcgpleHBvcnQgZnVuY3Rpb24gdDEoKTogYm9vbCB7IHJldHVybiAiXHUwMzlGXHUwMzk0XHUwMzlGXHUwM0EzIi50b0xvd2VyQ2FzZSgpID09ICJcdTAzQkZcdTAzQjRcdTAzQkZcdTAzQzIiOyB9CmV4cG9ydCBmdW5jdGlvbiB0MigpOiBib29sIHsgcmV0dXJuICJcdTAzOTcgXHUwMzlGXHUwMzk0XHUwMzlGXHUwM0EzIi50b0xvd2VyQ2FzZSgpID09ICJcdTAzQjcgXHUwM0JGXHUwM0I0XHUwM0JGXHUwM0MyIjsgfQpleHBvcnQgZnVuY3Rpb24gdDMoKTogYm9vbCB7IHJldHVybiAiMSBBXHUwM0EzIi50b0xvd2VyQ2FzZSgpID09ICIxIGFcdTAzQzIiOyB9CiMhaHRtbAo8cHJlIGlkPSJvdXQiPjwvcHJlPgo8c2NyaXB0IHR5cGU9Im1vZHVsZSI+CmNvbnN0IGUgPSBhd2FpdCBpbnN0YW50aWF0ZShhd2FpdCBjb21waWxlKCksIHt9KTsKZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoIm91dCIpLnRleHRDb250ZW50ID0gWwogICJ0MSgpID0gIiArIGUudDEoKSArICIgIChleHBlY3RlZCB0cnVlKSIsCiAgInQyKCkgPSAiICsgZS50MigpICsgIiAgKGV4cGVjdGVkIHRydWUpIiwKICAidDMoKSA9ICIgKyBlLnQzKCkgKyAiICAoZXhwZWN0ZWQgdHJ1ZSkiCl0uam9pbigiXG4iKTsKPC9zY3JpcHQ+

Click Run: t1 (single word) prints true, but t2 and t3 (a space before the word) print false.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions