#18409991 : 한 문단에 링크가 여러개 있을 경우, 첫번째 링크 텍스트에만 A 태그가 생성되던 버그 수정

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6906 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
taggon 2009-11-02 08:03:13 +00:00
parent d19d647926
commit fde8e04aa9
2 changed files with 20 additions and 5 deletions

View file

@ -1,5 +1,13 @@
(function($){
var url_regex = /((http|https|ftp|news|telnet|irc):\/\/(([0-9a-z\-._~!$&'\(\)*+,;=:]|(%[0-9a-f]{2}))*\@)?((\[(((([0-9a-f]{1,4}:){6}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(::([0-9a-f]{1,4}:){5}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(([0-9a-f]{1,4})?::([0-9a-f]{1,4}:){4}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){3}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){2}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4})|((([0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::))|(v[0-9a-f]+.[0-9a-z\-._~!$&'\(\)*+,;=:]+))\])|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))|(([0-9a-z\-._~!$&'\(\)*+,;=]|(%[0-9a-f]{2}))+))(:[0-9]*)?(\/([0-9a-z\-._~!$&'\(\)*+,;=:@]|(%[0-9a-f]{2}))*)*(\?([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?(#([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?)/i;
var protocol_re = '(https?|ftp|news|telnet|irc)://';
var domain_re = '(?:[\\w\\-]+\\.)+(?:[a-z]+)';
var max_255_re = '(?:1[0-9]{2}|2[0-4][0-9]|25[0-5])';
var ip_re = '(?:'+max_255_re+'\\.){3}'+max_255_re;
var port_re = '(?::([0-9]+))?';
var path_re = '((?:/[\\w!"$-/:-@]+)*)';
var hash_re = '(?:#([\\w!-@]+))?';
var url_regex = new RegExp('('+protocol_re+'('+domain_re+'|'+ip_re+')'+port_re+path_re+hash_re+')', 'ig');
var AutoLink = xe.createPlugin("autolink", {
targets : [],
@ -35,10 +43,14 @@
$(obj)
.contents()
.each(function(){
// FIXED: When this meanless code wasn't executed, url_regex do not run correctly. why?
url_regex.exec('');
if (!$(this).is('a,pre,xml,code,script,style,:input')) {
if (this.nodeType == 3 && url_regex.test(this.nodeValue)) { // text node
thisPlugin.targets.push(this);
} else {
thisPlugin.extractTargets(this);
}
}

View file

@ -51,14 +51,15 @@ describe('AutoLink functionality', {
value_of( $('#test5').contents().length ).should_be(3);
},
"#test6 - complex example" : function() {
value_of( $('#test6 a').length ).should_be(3);
value_of( $('#test6 a').length ).should_be(4);
value_of( $('#test6 a').eq(0).attr('href') ).should_be($('#test6 a').eq(0).text());
value_of( $('#test6 a').eq(1).parent().is('b') ).should_be_true();
value_of( $('#test6 a').eq(2).parent().is('b') ).should_be_true();
value_of( $('#test6 > textarea > a').length ).should_be(0);
value_of( $('#test6 > div > a').attr("target") ).should_be("_self");
}
});
describe('Autolink trigger', {
"#test7 - ignored" : function() {
value_of( $('#test7 > a').length ).should_be(0);
@ -68,6 +69,7 @@ describe('Autolink trigger', {
}
});
});
// ]]></script>
</head>
@ -79,8 +81,9 @@ describe('Autolink trigger', {
<div id="test4">http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1</div>
<div id="test5">Before text. http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1 After Text</div>
<div id="test6">
This is text. http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1 Text Text
<b>Bold text and http://mail.abc.com/path/to/some_program?hello=world#hash_text Bold text end</b>
This is text. http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1 Text Text.
Another URL : http://www.decccccf12312.co.uk/path/to/program?mymy=lovelove. XE!
<b>Bold text and http://mail.abc.com/path/to/one_cgi.cgi?hello=world#hash_text Bold text end</b>
<textarea>this text should be ignored http://mygony.com ignored?</textarea>
<div>
Hello~