Page 1 of 1

If VAR <> ; false, while StrLen(VAR) > 0

Posted: 02 Feb 2018, 05:23
by rousni
When VAR contains one or more zero-width spaces, and StringCaseSense Locale
If VAR <> ; false, while StrLen(VAR) > 0

Code: Select all

StringCaseSense Locale
VAR := "‌‍‌"
MsgBox % StrLen(VAR) ; 3 (3 zero-width spaces)
If VAR =
    MsgBox Isn't this a bug

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 02 Feb 2018, 07:33
by just me
I'd say this is a bug:

Code: Select all

MsgBox % StrLen(VAR) ; 3 (3 zero-width spaces)
Edit: I didn't notice the three invisible characters in Var := "".

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 02 Feb 2018, 08:07
by jeeswg
It does seem to be bug-like. Btw the 3 characters you use are 8204, 8205, 8204.

Code: Select all

q:: ;test zero-width characters with StringCaseSense Locale
StringCaseSense, Locale

;note: two invisible characters are listed here:
;8204	200C	‌	ZERO WIDTH NON-JOINER
;8205	200D	‍	ZERO WIDTH JOINER

VAR := Chr(8204) Chr(8205) Chr(8204)

MsgBox, % StrLen(VAR) ;3

if VAR =
	MsgBox, 1 ;1
else
	MsgBox, 0

if (VAR = "")
	MsgBox, 1 ;1
else
	MsgBox, 0
return

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 09 Feb 2018, 03:33
by lexikos
What makes you think that they aren't equal?

If a locale-sensitive comparison tells you the strings are equal, that is because the system considers the strings to be equal under the rules defined by the current locale. This behaviour comes directly from lstrcmpiW, which performs the comparison with CompareStringEx.

Code: Select all

s1 := "a‌‍‌b"  ; there are 3 zero-width spaces in the middle
s2 := "ab"  ; just as it appears
MsgBox % (DllCall("lstrcmpiW", "wstr", s1, "wstr", s2) ? "not" : "") " equal"
MsgBox % (DllCall("CompareStringEx", "ptr", 0, "uint", 0x10
    , "wstr", s1, "int", -1, "wstr", s2, "int", -1
    , "ptr", 0, "ptr", 0, "ptr", 0)=2 ? "" : "not") " equal"

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 12 Feb 2018, 13:25
by jeeswg
Thanks for the info lexikos. Here's a little test.

Code: Select all

;4511 characters were regarded as equal to a blank string
q:: ;test StringCaseSense Locale, characters equal to a blank string
vOutput := ""
VarSetCapacity(vOutput, 100000*2)
StringCaseSense, Locale
vOutput := "", vCount := 0
Loop, 65535
	if (Chr(A_Index) = "")
		vOutput .= A_Index "`t" Chr(A_Index) "`r`n", vCount += 1
Clipboard := vCount "`r`n" vOutput
MsgBox, % Clipboard
return

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 05 Apr 2018, 15:17
by Yer
Found this thread after reading about sneaky uses of zero width characters here https://www.ghacks.net/2018/04/05/how-t ... rprinting/ . Can someone tell me if and how AutoHotkey can be used to strip away all such zero width characters from any string? I'd like to make a hotkey to scrub the clipboard of such characters and then paste.

Re: If VAR <> ; false, while StrLen(VAR) > 0

Posted: 17 Aug 2018, 12:20
by rousni

Code: Select all

StringCaseSense Locale
X = �
If (X = "")
	MsgBox Buggy 'StringCaseSense Locale' definitins