Correct result of Stem()
diff --git a/src/strutil.cc b/src/strutil.cc
index 51ffa4f..8c4bdc0 100644
--- a/src/strutil.cc
+++ b/src/strutil.cc
@@ -161,7 +161,7 @@
   if (!Match(str))
     return "";
   return str.substr(percent_index_,
-                    str.size() - (pat_.size() - percent_index_ - 1));
+                    str.size() - pat_.size() + 1);
 }
 
 void Pattern::AppendSubst(StringPiece str,
diff --git a/testcase/stem_middle.mk b/testcase/stem_middle.mk
new file mode 100644
index 0000000..cce73ae
--- /dev/null
+++ b/testcase/stem_middle.mk
@@ -0,0 +1,11 @@
+
+test: a/a.a b.b c/c
+
+a/%.a:
+	@echo $*
+
+%.b:
+	@echo $*
+
+c/%:
+	@echo $*