wiki: external links must have a scheme

git-svn-id: trunk@35636 -
This commit is contained in:
mattias 2012-03-01 13:48:36 +00:00
parent d29aa457ba
commit 0e62addd5c

View File

@ -974,6 +974,8 @@ begin
end; end;
procedure TWikiPage.HandleEdgedBracketOpen; procedure TWikiPage.HandleEdgedBracketOpen;
var
p: PChar;
begin begin
if FCurP[1] in [#0..#31,' '] then begin if FCurP[1] in [#0..#31,' '] then begin
inc(FCurP); inc(FCurP);
@ -996,6 +998,11 @@ begin
end else begin end else begin
// external link // external link
// for example [url|caption] or [url caption] // for example [url|caption] or [url caption]
p:=FCurP;
if not IsIdentStartChar[p^] then exit; // not a valid scheme
inc(p);
while IsIdentChar[p^] do inc(p);
if (p^<>':') or (p[1]<>'/') or (p[2]<>'/') then exit; // not a valid scheme
FLinkToken.SubToken:=wptExternLink; FLinkToken.SubToken:=wptExternLink;
FLinkToken.LinkStartPos:=StrPos(FCurP); FLinkToken.LinkStartPos:=StrPos(FCurP);
while not (FCurP^ in [#0..#31, ' ' , '|' , ']']) do inc(FCurP); while not (FCurP^ in [#0..#31, ' ' , '|' , ']']) do inc(FCurP);
@ -1013,6 +1020,7 @@ begin
FLinkToken.CaptionEndPos:=FLinkToken.LinkEndPos; FLinkToken.CaptionEndPos:=FLinkToken.LinkEndPos;
end; end;
end; end;
if (BaseURL<>'') if (BaseURL<>'')
and (LeftStr(FLinkToken.Link,length(BaseURL))=BaseURL) then begin and (LeftStr(FLinkToken.Link,length(BaseURL))=BaseURL) then begin
// a link to a wiki page, but with full URL => shorten // a link to a wiki page, but with full URL => shorten
@ -1021,6 +1029,7 @@ begin
while (FLinkToken.Link<>'') and (FLinkToken.Link[1]='/') do while (FLinkToken.Link<>'') and (FLinkToken.Link[1]='/') do
Delete(FLinkToken.Link,1,1); Delete(FLinkToken.Link,1,1);
end; end;
if FCurP^='|' then begin if FCurP^='|' then begin
// link with caption // link with caption
inc(FCurP); inc(FCurP);