From 4caefedbbc1b410dfc79c981fe66c12f7baf4d44 Mon Sep 17 00:00:00 2001
From: Michael Aaron Murphy <mmstickman@gmail.com>
Date: Mon, 19 Jun 2017 12:32:59 -0400
Subject: [PATCH] Glob Fixes

---
 examples/glob.ion                |  8 ++++++++
 examples/glob.out                |  3 +++
 src/parser/shell_expand/mod.rs   |  2 --
 src/parser/shell_expand/words.rs | 13 +++++--------
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/examples/glob.ion b/examples/glob.ion
index 10497d63..ff060ea4 100644
--- a/examples/glob.ion
+++ b/examples/glob.ion
@@ -6,3 +6,11 @@ echo Cargo.*
 echo Cargo?toml
 echo Cargo.[tqr]oml
 echo examples/[ef]*.ion
+mkdir glob_test
+touch glob_test/{one,two,three}
+cd glob_test
+echo *
+echo *[wh]*
+echo [t]*
+cd ..
+rm glob_test -R
diff --git a/examples/glob.out b/examples/glob.out
index 77ac6085..5f262d26 100644
--- a/examples/glob.out
+++ b/examples/glob.out
@@ -6,3 +6,6 @@ Cargo.lock Cargo.toml
 Cargo.toml
 Cargo.toml
 examples/else_if.ion examples/fail.ion examples/fibonacci.ion examples/fn.ion examples/for.ion
+one three two
+three two
+three two
diff --git a/src/parser/shell_expand/mod.rs b/src/parser/shell_expand/mod.rs
index bb179b6c..5a04421f 100644
--- a/src/parser/shell_expand/mod.rs
+++ b/src/parser/shell_expand/mod.rs
@@ -254,7 +254,6 @@ pub fn expand_tokens<'a>(token_buffer: &[WordToken], expand_func: &'a ExpanderFu
                         slice_string(&mut output, &expanded, index);
                     },
                     WordToken::Normal(text,true) => {
-                        //if this is a normal string that can be globbed, do it!
                         let globbed = glob(text);
                         if let Ok(var)=globbed{
                             for path in var.filter_map(Result::ok) {
@@ -431,7 +430,6 @@ pub fn expand_tokens<'a>(token_buffer: &[WordToken], expand_func: &'a ExpanderFu
                     output.push_str(text);
                 },
                 WordToken::Normal(text,true) => {
-                    //if this is a normal string that can be globbed, do it!
                     let globbed = glob(text);
                     if let Ok(var)=globbed{
                         is_glob=true;
diff --git a/src/parser/shell_expand/words.rs b/src/parser/shell_expand/words.rs
index 3f44c90c..58a8e90b 100644
--- a/src/parser/shell_expand/words.rs
+++ b/src/parser/shell_expand/words.rs
@@ -814,7 +814,6 @@ impl<'a> Iterator for WordIterator<'a> {
         let mut start = self.read;
         let mut glob = false;
         loop {
-
             if let Some(character) = iterator.next() {
                 match character {
                     _ if self.flags & BACKSL != 0 => {
@@ -905,10 +904,10 @@ impl<'a> Iterator for WordIterator<'a> {
                             }
                         }
                     },
-                    b'*'|b'?' => {
-                        // if a word is not special, make sure you return the globbed variant at the end
-                        self.read+=1;
-                        glob=true; //warning is incorrect it does get read
+                    b'*' | b'?' => {
+                        self.read += 1;
+                        glob = true;
+                        break
                     },
                     _ => { self.read += 1; break },
                 }
@@ -961,9 +960,8 @@ impl<'a> Iterator for WordIterator<'a> {
                     }
                 },
                 b'*'|b'?' if self.flags & SQUOTE == 0 => {
-                    // if a word is not special, make sure you return the globbed variant at the end
                     self.read += 1;
-                    glob = true; //warning is incorrect it does get read
+                    glob = true;
                 },
                 _ => (),
             }
@@ -973,7 +971,6 @@ impl<'a> Iterator for WordIterator<'a> {
         if start == self.read {
             None
         } else {
-            //println!("Normal exit");
             Some(WordToken::Normal(&self.data[start..],glob))
         }
     }
-- 
GitLab