]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0500: filetype: some html files wrongly recognized as htmlangular v9.2.0500
authortruffle <truffleagent@gmail.com>
Mon, 18 May 2026 20:46:24 +0000 (20:46 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 18 May 2026 20:46:24 +0000 (20:46 +0000)
Problem:  filetype: some html files are wrongly recognized as htmlangular
Solution: Use the \< atom to anchor ng-template and ng-content to start
          of word (truffle)

Prevent false-positive htmlangular detection on words containing
'ng-template' or 'ng-content' as a substring (e.g. 'song-template',
'sing-content'). Anchor both branches with \< to require a word start,
matching the \<DTD\s\+XHTML\s idiom used five lines below.

related: neovim/neovim#39778.
closes:  #20246

Signed-off-by: truffle <truffleagent@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/ft.vim
src/testdir/test_filetype.vim
src/version.c

index 3085f3575c2fadc214443595b07afa50fe31341c..c2f3e2afd0612623baeb93f7191effe228f8bfba 100644 (file)
@@ -3,7 +3,7 @@ vim9script
 # Vim functions for file type detection
 #
 # Maintainer:          The Vim Project <https://github.com/vim/vim>
-# Last Change:         2026 May 16
+# Last Change:         2026 May 18
 # Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 # These functions are moved here from runtime/filetype.vim to make startup
@@ -547,7 +547,7 @@ export def FThtml()
 
   while n < 40 && n <= line("$")
     # Check for Angular
-    if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|ng-template\|ng-content'
+    if getline(n) =~ '@\(if\|for\|defer\|switch\)\|\*\(ngIf\|ngFor\|ngSwitch\|ngTemplateOutlet\)\|\<ng-template\|\<ng-content'
       setf htmlangular
       return
     endif
index 70ac4010612af26137e6eff98f52b7e30d9fcabf..47df92d0bd915d69c131066d44dd19e355024546 100644 (file)
@@ -1888,6 +1888,27 @@ func Test_html_file()
   call assert_equal('htmlangular', &filetype)
   bwipe!
 
+  " HTML Angular ng-template element
+  let content = ['<ng-template let-foo>{{ foo }}</ng-template>']
+  call writefile(content, 'Xfile.html', 'D')
+  split Xfile.html
+  call assert_equal('htmlangular', &filetype)
+  bwipe!
+
+  " HTML Angular ng-content element
+  let content = ['<div><ng-content select="[item]"></ng-content></div>']
+  call writefile(content, 'Xfile.html', 'D')
+  split Xfile.html
+  call assert_equal('htmlangular', &filetype)
+  bwipe!
+
+  " Word containing 'ng-template' as a suffix must not trigger htmlangular
+  let content = ['<div class="song-template">', '  <h1>Not Angular</h1>', '</div>']
+  call writefile(content, 'Xfile.html', 'D')
+  split Xfile.html
+  call assert_equal('html', &filetype)
+  bwipe!
+
   " Django Template
   let content = ['{% if foobar %}',
       \ '    <ul>',
index 4ce61756502c4e830ed258823162bea9040b6a79..bb0b3d4f5322a88bbe62ee97d7b2d37854f7f9ab 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    500,
 /**/
     499,
 /**/