Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by garry » 26 Aug 2021, 04:45

man kann aus dem Script eine Funktion erstellen
hier nur ein Beispiel mit gosub ( added Funktion 'internetconnected' )

Code: Select all

#warn
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"  ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- nicht correct aber umgeleitet d.h URL exist
urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- URL falsch not exist
;- case-1 INTERNETCONNECTED  ( modem / wlan )
aaa:= InternetConnected()
if aaa=0
  {
  msgbox, 262208,InternetCheck,Internet NOT connected
  exitapp
  }
msgbox, 262208,InternetCheck ,Internet OK
;----------------------------------------------
;- continue here to check if URL exist
;----------------------------------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
gosub,a1
;------------
if (result=1)
   {
   msgbox, 262208,SUCCESS,URL=%urlx%=`nURL exists
   ;- continue here if OK
   }
if (result=0)
   {
   msgbox, 262208,NO SUCCESS,URL=%urlx%=`nURL NOT exists
   exitapp
   }
return
;--------- gosub check URL -------------------
a1:
try {
    xx.Open("GET",urlx)
    xx.Send()
    result=1
} catch e {
    result=0
    }
return
;==================================================================
internetConnected(){ ;https://autohotkey.com/boards/viewtopic.php?f=5&t=23127
    static url:="http://google.com"                         ;-user masonjar13
    if(!dllCall("Wininet.dll\InternetGetConnectedState","Str","","Int",0))
        return 0
    if(!dllCall("Wininet.dll\InternetCheckConnection","Str",url,"Uint",1,"Uint",0))
        return 0
    return 1
}
;==================================================================

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 25 Aug 2021, 09:25

Hallo garry und vielen Dank, aber ich fürchte, das ist jetzt alles zu hoch für mich, jedenfalls ohne Erläuterungen. Mir liegt nur daran, dass IsUrl() diese exotischen WP-Urls als Urls erkennt. Grüße!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by garry » 25 Aug 2021, 07:25

hier noch 2 Beispiele
in diesem script beide benutzt für Test

Code: Select all

;-------- saved at Montag, 7. Juli 2014 08:15:52 --------------
;-------- https://autohotkey.com/board/topic/112151-checking-network-status/
;- CHECK internet connection & URL ------------------------------------------------

;urlx:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"                    ;- correct
urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"  ;- correct
;urlx:="https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- nicht correct aber umgeleitet
;urlx:="https://en.wikipediax.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A1"  ;- URL falsch not exist
;----
;urlx:="https://www.radio.de/s/hpr1classiccountry"
;urlx:="http://87.98.130.255:8188/stream"          ;- HPR1 classic country
;urlx:="http://87.98.130.255:8188/played.html"
goto,example1

example1:
FLAG_ICC_FORCE_CONNECTION=1
if !DllCall("Wininet.dll\InternetGetConnectedState", "UInt*", flag, "UInt", 0)
       {
	aa1:= % "InternetGetConnectedState() failed " flag " " A_LastError
        msgbox, 262208,NO SUCCES,AA1=%aa1%
	return
        }
flagstr =
if (flag & 0x01)
	flagstr .= "INTERNET_CONNECTION_MODEM`n"
if (flag & 0x02)
	flagstr .= "INTERNET_CONNECTION_LAN`n"
if (flag & 0x04)
	flagstr .= "INTERNET_CONNECTION_PROXY`n"
if (flag & 0x10)
	flagstr .= "INTERNET_RAS_INSTALLED`n"
if (flag & 0x20)
	flagstr .= "INTERNET_CONNECTION_OFFLINE`n"
if (flag & 0x40)
	flagstr .= "INTERNET_CONNECTION_CONFUGURED`n"
aa3:= % flagstr "InternetGetConnectedState() succeed " flag
if !DllCall("Wininet.dll\InternetCheckConnection", "Str",urlx,"UInt", FLAG_ICC_FORCE_CONNECTION, "UInt", 0)
        {
	aa2:= % "InternetCheckConnection() failed " A_LastError
        msgbox, 262208,NO SUCCES,AA2=%aa2%
	return
        }
;msgbox,aa3=%aa3%
;return


example2:
;--- example for try/catch/error CHECK URL ------------------
xx:=ComObjCreate("WinHttp.WinHttpRequest.5.1")   ;-Create the Object
;-- catch get error but don't show failure
;ComObjError(false)
;xx.Silent := True    ;- script failure = off
xx.SetTimeouts(500,500,500,500)
try {
    xx.Open("GET",urlx)                           ;-Open communication
    xx.Send()                                   ;-Send the "get" request
    aac=
    aac:=xx.ResponseText                        ;-Set the "aac" variable to the response
    ;msgbox, 262208,%urlx% exists,%aa4%`n`n%urlx%`n-----------------`n %aac%
} catch e {
    xxx:=e.Message
    msgbox, 262208,NO SUCCESS ERROR ,AA3=%aa3%`n------------`nError=Catch`n%urlx%`n NOT exists`n------------------------------------------`n%xxx%`n------------------------------------------,
    return
    }
msgbox, 262208,SUCCESS,AA3=%aa3%`n------------`nURL EXISTS=`n%urlx%
return
;==================================================================

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 25 Aug 2021, 05:08

Hallo just me, die zweite Url scheint schon gültig zu sein, weil sie direkt aus WP kopiert ist und im Übrigen beim Draufklicken auch ordnungsgemäß fuinktioniert. Grüße!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by just me » 25 Aug 2021, 04:53

Johnny R wrote: Hallo, ich hatte schon wieder mit einer Wikipedia-Url zu tun, die von der Funktion nicht als Url erkannt wird, nämlich
MsgBox % IsUrl("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Kann man da etwas machen oder ist dieser String zu exotisch? Grüße!
Moin,

diese URL funktioniert hier mit:

Code: Select all

MsgBox % IsUrl2("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
MsgBox % IsUrl2("https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")


IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$")
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}
Bei der zweiten URL scheitert es am letzten Slash /. Wenn die URL gültig ist, müsste die Prüfung im RegEx noch mal geändert werden.

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 25 Aug 2021, 03:52

Hallo garry, vielen Dank für Deine Mühe. Beim Testen ergab sich aber, dass die Funktion mit einer anderen WP-Url immer noch nicht funktioniert, nämlich
MsgBox % IsUrlString("https://en.wikipedia.org/wiki/Special:Contributions/%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Das Ding ist offenbar ein Buch mit sieben Siegeln...

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by garry » 24 Aug 2021, 14:54

function von user @haichen und @teadrinker

Code: Select all

;- URL encode-decode    user 'teadrinker'
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84825&p=372265#p372265

;url2:="https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%E6%9D%8E%E9%A6%99%E8%98%AD"
;url2:="https%3A%2F%2F%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82_%D0%A1%D0%BF%D0%B0%D1%81%D0%B8%D0%B1%D0%BE_%D0%B1%D0%BE%D0%BB%D1%8C%D1%88%D0%BE%D0%B5_stackoverflow.com%2F"
url2:="https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3"
decoded := EncodeDecodeURI(url2, false)
encoded := EncodeDecodeURI(decoded)
isurl:=IsUrl2(decoded)
msgbox,ORIG=`n%url2%`n-------------------------------------------------`nDECODED=`n%decoded%`n-------------------------------------------------`nENCODED=`n%encoded%`n-------------------------------------------------`nISURL=%isurl%
return
;---------------
;- from user 'teadrinker'
EncodeDecodeURI(str, encode := true, component := true) {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate("htmlfile")
      Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
      JS := Doc.parentWindow
      ( Doc.documentMode < 9 && JS.execScript() )
   }
   Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
;=============================================================================
;- https://www.autohotkey.com/boards/viewtopic.php?f=9&t=70336&start=20     user 'haichen'
IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$") 
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}
;=============================================================================

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 24 Aug 2021, 07:30

Hallo, ich hatte schon wieder mit einer Wikipedia-Url zu tun, die von der Funktion nicht als Url erkannt wird, nämlich
MsgBox % IsUrl("https://en.wikipedia.org/wiki/User:%CE%9F%CE%A5%CE%A4%CE%99%CE%A3")
Kann man da etwas machen oder ist dieser String zu exotisch? Grüße!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 08 Dec 2019, 13:24

haichens letzte Version vom 5.12.2019 funktioniert jetzt bei mir seit einigen Tagen fehlerfrei. Danke nochmals!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 05 Dec 2019, 12:19

Danke an alle! Für den Augenblick funktioniert diese Fassung jetzt scheinbar, vorläufig bis auf Weiteres!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by haichen » 05 Dec 2019, 11:23

Ich habe neben dem zuvor reparierten noch einen zweiten Regex, der mit einem CALLOUT arbeitet.

Code: Select all

IsURL2(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d+)(?CCallout))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$") 
}

Callout(m) {
  if ((m.port<=65535) and (m.port>0))
    return 0
  return -1 ;the complete regexp fails
}

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by haichen » 05 Dec 2019, 10:48

Uuuh Mist. Danke just me, das du da noch mal drüber geschaut hast.
Meine Lösung (Erleuchtung in der Düsternis :idea:):

Code: Select all

*((SubPat.port<=65535) and (SubPat.port>0) or (SubPat.port=""))
Ist das besser?

Hier noch mal komplett:

Code: Select all

url1=https://de.wikipedia.org:0/wiki/Wikipedia:Hauptfenster         ;0
url2=https://de.wikipedia.org:1/wiki/Wikipedia:Hauptfenster         ;1
url3=https://de.wikipedia.org:65536/wiki/Wikipedia:Hauptfenster     ;0
url4=https://de.wikipedia.org:65535/wiki/Wikipedia:Hauptfenster     ;1
url5=https://de.wikipedia.org:65535                                 ;1
url6=https://de.wikipedia.org:65535/wiki:test/                      ;0
url7=https://de.wikipedia.org/wiki/Wikipedia:Hauptfenster           ;1
url8=https://de.wikipedia.org                                       ;1
msgbox, % IsURL(URL1) IsURL(URL2) IsURL(URL3) IsURL(URL4) IsURL(URL5) IsURL(URL6) IsURL(URL7) IsURL(URL8) ;Resultat 01011011

return

IsURL(sURL) {
   Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d{1,5})(?!\d+/))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$",SubPat)*((SubPat.port<=65535) and (SubPat.port>0) or (SubPat.port=""))
}

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by just me » 05 Dec 2019, 09:25

Moin,

ich würde denken, dass die letzte Version von haichen

Code: Select all

*(SubPat.port<=65535)and(SubPat.port>0)
nur dann funktioniert, wenn die URL tatsächlich eine Portangabe in diesem Bereich enthält.

-> Ohne Port sieht's düster aus!

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by nnnik » 05 Dec 2019, 08:04

Das Skript an sich ist leicht problematisch. Ich habe eine Version die anders strukturiert ist und von daher keinerlei Probleme verursachen sollte.
Ich werde sie später mal raussuchen.

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 05 Dec 2019, 07:36

Ich muss leider berichten, dass die letzte Fassung des RegEx bei mir aus völlig klandestinen Gründen einen Fehler 0x800706B5 - Die Schnittstelle ist unbekannt in atnbuenos Script beim Aufruf bestimmter ACC-Funktionen erzeugt:

Code: Select all

---------------------------
ShortCut.ahk
---------------------------
Error in #include file "A:\System\AHK\ACC.ahk":
     0x800706B5 - Die Schnittstelle ist unbekannt.
Source:		(null)
Description:	(null)
HelpFile:		(null)
HelpContext:	0

Specifically: accChildCount

	Line#
	110: Return,p=""?setting:setting:=p
	111: }
	112: {
	113: if ComObjType(Acc,"Name") != "IAccessible"  
	114: ErrorLevel := "Invalid IAccessible Object"
	115: Else
	115: {
--->	116: Acc_Init(), cChildren:=Acc.accChildCount, Children:=[]  
	117: if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0  
	117: {
	118: Loop,%cChildren%
	119: i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?Acc_Query(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):  
	120: Return,Children.MaxIndex()?Children:
	121: }
	121: Else

Continue running the script?
---------------------------
Ja   Nein   
---------------------------
Die vorletzte Fassung des RegEx erzeugt diesen Fehler nicht, weshalb ich diese wiederhergestellt habe.

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by Johnny R » 04 Dec 2019, 11:33

@haichen, vielen Dank! Es gibt offenbar wirklich nichts gutes, was sich nicht doch noch verbessern lässt...

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by nnnik » 04 Dec 2019, 10:09

Danke - habe es auch in mein Skript eingebaut :thumbup:

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by haichen » 04 Dec 2019, 05:58

Ich hatte Lust hier auch die Portnummern von 1-65535 abzudecken. Falls die 0 auch dazugehört, oder die Portnummern in einer url erst ab 10 zählen, kann man das einfach ändern.
url1=https://de.wikipedia.org:0/wiki/Wikipedia:Hauptfenster
url2=https://de.wikipedia.org:1/wiki/Wikipedia:Hauptfenster
url3=https://de.wikipedia.org:65536/wiki/Wikipedia:Hauptfenster
url4=https://de.wikipedia.org:65535/wiki/Wikipedia:Hauptfenster
url5=https://de.wikipedia.org:65535
url6=https://de.wikipedia.org:65535/wiki:test/
msgbox, % IsURL(URL1) IsURL(URL2) IsURL(URL3) IsURL(URL4) IsURL(URL5) IsURL(URL6) ;erwartetes Resultat 010110

return

IsURL(sURL) {
Return RegExMatch(sURL, "iO)^(?<Protocol>https?|ftp)://(?<Domain>(?:[\w-]+\.)+\w\w+)(?::(?<Port>\d{1,5})(?!\d+/))?/?(?!.*:.*/)(?<Path1>(?:[^:/?# ]*/?))/?(?<Path2>(?:[^/?# ]*/?)+)(?:\?(?<Query>[^#]+)?)?(?:\#(?<Hash>.+)?)?$",SubPat)*(SubPat.port<=65535)and(SubPat.port>0)
}

Re: Die Funktion IsUrl() streikt bei einem Doppelpunkt

Post by haichen » 03 Dec 2019, 14:23

Schön, freut mich das es funktioniert.😁

Top