Disambiguate .cfc files: a ColdFusion component may be written in the script * dialect ("component { ... }", parsed by the JS-like cfscript grammar) or the * tag dialect (" ... ", parsed by the HTML-derived cfml * grammar). The extension table defaults to cfscript because that is what modern * Lucee/ACF templates use, but large legacy codebases are predominantly tag-ba
| 1539 | * - anything else ("component { ... }") ⇒ cfscript. |
| 1540 | * Defaults to CBM_LANG_CFSCRIPT on any doubt (preserves table behaviour). */ |
| 1541 | static CBMLanguage lang_cfc_text(const char *buf) { |
| 1542 | /* Rule 1: explicit tag-component markers ⇒ tag dialect. */ |
| 1543 | if (cbm_strcasestr(buf, "<cfcomponent") != NULL || cbm_strcasestr(buf, "<cffunction") != NULL) { |
| 1544 | return CBM_LANG_CFML; |
| 1545 | } |
| 1546 | |
| 1547 | /* Rule 2: locate the first significant token, past whitespace and comments. */ |
| 1548 | const char *p = buf; |
| 1549 | for (;;) { |
| 1550 | while (*p && isspace((unsigned char)*p)) { |
| 1551 | p++; |
| 1552 | } |
| 1553 | if (starts_with_ci(p, "<!---")) { |
| 1554 | const char *end = strstr(p + SLEN("<!---"), "--->"); |
| 1555 | if (!end) { |
| 1556 | break; /* comment runs past the buffer — treat as no token */ |
| 1557 | } |
| 1558 | p = end + SLEN("--->"); |
| 1559 | continue; |
| 1560 | } |
| 1561 | break; |
| 1562 | } |
| 1563 | if (*p == '<') { |
| 1564 | /* A leading <cfscript> wrapper is script content; any other leading tag |
| 1565 | * (bare-tag file) is tag content. */ |
| 1566 | return starts_with_ci(p, "<cfscript") ? CBM_LANG_CFSCRIPT : CBM_LANG_CFML; |
| 1567 | } |
| 1568 | return CBM_LANG_CFSCRIPT; |
| 1569 | } |
| 1570 | |
| 1571 | CBMLanguage cbm_disambiguate_cfc(const char *path) { |
| 1572 | unsigned char head[LANG_PROBE_CFC]; |
no test coverage detected