Skip to content

Commit

Permalink
fixed bug where self-closing html tags would act as open tags
Browse files Browse the repository at this point in the history
  • Loading branch information
EndangeredMassa authored and madrobby committed Apr 28, 2012
1 parent c84f926 commit 1c3325d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source :rubygems

gem 'rake'
gem 'uglifier'
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
GEM
remote: http://rubygems.org/
specs:
execjs (1.3.0)
multi_json (~> 1.0)
multi_json (1.3.2)
rake (0.9.2.2)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)

PLATFORMS
ruby

DEPENDENCIES
rake
uglifier
4 changes: 4 additions & 0 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Zepto = (function() {
getComputedStyle = document.defaultView.getComputedStyle,
cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 },
fragmentRE = /^\s*<(\w+|!)[^>]*>/,
tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,

// Used by `$.zepto.init` to wrap elements, text/comment nodes, document,
// and document fragment node types.
Expand Down Expand Up @@ -101,6 +102,9 @@ var Zepto = (function() {
if (name === undefined) name = fragmentRE.test(html) && RegExp.$1
if (!(name in containers)) name = '*'
var container = containers[name]

if(html.replace) html = html.replace(tagExpanderRE, "<$1></$2>")

container.innerHTML = '' + html
return $.each(slice.call(container.childNodes), function(){
container.removeChild(this)
Expand Down
3 changes: 3 additions & 0 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ <h1>Zepto DOM unit tests</h1>
t.assertEqual("<span>world</span>", outerHTML(fragment.get(2)))
t.assertEqual('', fragment.selector)

fragment = $("<div /><div />")
t.assertLength(2, fragment)

fragment = $("<div>hello</div> ")
t.assertLength(1, fragment)
},
Expand Down

0 comments on commit 1c3325d

Please sign in to comment.