@@ -323,6 +323,9 @@ func (ti *TemplInfo) findBestMatchBaseof(s *TemplateStore, d1 TemplateDescriptor
323
323
}
324
324
325
325
ti .baseVariants .WalkPath (k1 , func (k2 string , v map [TemplateDescriptor ]* TemplWithBaseApplied ) (bool , error ) {
326
+ if ! s .inPath (k1 , k2 ) {
327
+ return false , nil
328
+ }
326
329
slashCountK2 := strings .Count (k2 , "/" )
327
330
distance := slashCountK1 - slashCountK2
328
331
@@ -615,6 +618,9 @@ func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo {
615
618
defer s .putBest (best )
616
619
617
620
s .treeShortcodes .WalkPath (k1 , func (k2 string , m map [string ]map [TemplateDescriptor ]* TemplInfo ) (bool , error ) {
621
+ if ! s .inPath (k1 , k2 ) {
622
+ return false , nil
623
+ }
618
624
slashCountK2 := strings .Count (k2 , "/" )
619
625
distance := slashCountK1 - slashCountK2
620
626
@@ -780,8 +786,18 @@ func (s *TemplateStore) findBestMatchGet(key string, category Category, consider
780
786
}
781
787
}
782
788
789
+ func (s * TemplateStore ) inPath (k1 , k2 string ) bool {
790
+ if k1 != k2 && ! strings .HasPrefix (k1 , k2 + "/" ) {
791
+ return false
792
+ }
793
+ return true
794
+ }
795
+
783
796
func (s * TemplateStore ) findBestMatchWalkPath (q TemplateQuery , k1 string , slashCountK1 int , best * bestMatch ) {
784
797
s .treeMain .WalkPath (k1 , func (k2 string , v map [nodeKey ]* TemplInfo ) (bool , error ) {
798
+ if ! s .inPath (k1 , k2 ) {
799
+ return false , nil
800
+ }
785
801
slashCountK2 := strings .Count (k2 , "/" )
786
802
distance := slashCountK1 - slashCountK2
787
803
0 commit comments