Function only taking the first 4 elements of a character array
You are passing a pointer (char str[]) and the sizeof operator is giving you the size of that pointer (4 bytes it appears in your case - on some Arduinos it would be 2 bytes).

The length of a character array is found by using strlen - assuming the string is terminated by a null (0x00).