Permalink
Browse files

Fix #11 Mark properly when pattern ends in /

  • Loading branch information...
1 parent 4c2ce2e commit 1b0c0602fc95bd73c9f50ed9e945bc3afd461a3a @isaacs committed Sep 26, 2012
Showing with 69 additions and 4 deletions.
  1. +6 −4 glob.js
  2. +63 −0 test/mark.js
View
10 glob.js
@@ -200,12 +200,14 @@ Glob.prototype._finish = function () {
// at *some* point we statted all of these
all = all.map(function (m) {
var sc = this.statCache[m]
- if (!sc) return m
- if (m.slice(-1) !== "/" && (Array.isArray(sc) || sc === 2)) {
+ if (!sc)
+ return m
+ var isDir = (Array.isArray(sc) || sc === 2)
+ if (isDir && m.slice(-1) !== "/") {
return m + "/"
}
- if (m.slice(-1) === "/") {
- return m.replace(/\/$/, "")
+ if (!isDir && m.slice(-1) === "/") {
+ return m.replace(/\/+$/, "")
}
return m
}, this)
View
@@ -0,0 +1,63 @@
+var test = require("tap").test
+var glob = require('../')
+process.chdir(__dirname)
+
+test("mark, no / on pattern", function (t) {
+ glob("a/*", {mark: true}, function (er, results) {
+ if (er)
+ throw er
+ t.same(results, [ 'a/abcdef/',
+ 'a/abcfed/',
+ 'a/b/',
+ 'a/bc/',
+ 'a/c/',
+ 'a/cb/',
+ 'a/symlink/' ])
+ t.end()
+ })
+})
+
+test("mark=false, no / on pattern", function (t) {
+ glob("a/*", function (er, results) {
+ if (er)
+ throw er
+ t.same(results, [ 'a/abcdef',
+ 'a/abcfed',
+ 'a/b',
+ 'a/bc',
+ 'a/c',
+ 'a/cb',
+ 'a/symlink' ])
+ t.end()
+ })
+})
+
+test("mark=true, / on pattern", function (t) {
+ glob("a/*/", {mark: true}, function (er, results) {
+ if (er)
+ throw er
+ t.same(results, [ 'a/abcdef/',
+ 'a/abcfed/',
+ 'a/b/',
+ 'a/bc/',
+ 'a/c/',
+ 'a/cb/',
+ 'a/symlink/' ])
+ t.end()
+ })
+})
+
+test("mark=false, / on pattern", function (t) {
+ glob("a/*/", function (er, results) {
+ if (er)
+ throw er
+ t.same(results, [ 'a/abcdef/',
+ 'a/abcfed/',
+ 'a/b/',
+ 'a/bc/',
+ 'a/c/',
+ 'a/cb/',
+ 'a/symlink/' ])
+ t.end()
+ })
+})

0 comments on commit 1b0c060

Please sign in to comment.