@@ -544,3 +544,75 @@ describe('Nice to have: Boolean in various contexts', () => {
544544 assert . equal ( sql , 'UPDATE t SET `active` = true, `archived` = false' ) ;
545545 } ) ;
546546} ) ;
547+
548+ describe ( 'Critical: Backtick-quoted identifiers with comment-like sequences' , ( ) => {
549+ test ( 'database/table names with double dashes' , ( ) => {
550+ const sql = format (
551+ 'INSERT INTO `db--name`.`table`(`a`, `b`) VALUES (?, ?)' ,
552+ [ 1 , 'hello' ]
553+ ) ;
554+ assert . equal (
555+ sql ,
556+ "INSERT INTO `db--name`.`table`(`a`, `b`) VALUES (1, 'hello')"
557+ ) ;
558+ } ) ;
559+
560+ test ( 'column names with double dashes' , ( ) => {
561+ const sql = format (
562+ 'INSERT INTO t (`col--1`, `col--2`) VALUES (?, ?)' ,
563+ [ 1 , 2 ]
564+ ) ;
565+ assert . equal ( sql , 'INSERT INTO t (`col--1`, `col--2`) VALUES (1, 2)' ) ;
566+ } ) ;
567+
568+ test ( 'backticks with block comment markers' , ( ) => {
569+ const sql = format ( 'INSERT INTO `table/*name*/` VALUES (?)' , [ 1 ] ) ;
570+ assert . equal ( sql , 'INSERT INTO `table/*name*/` VALUES (1)' ) ;
571+ } ) ;
572+
573+ test ( 'escaped backticks inside identifiers' , ( ) => {
574+ const sql = format ( 'INSERT INTO `table``name` VALUES (?)' , [ 1 ] ) ;
575+ assert . equal ( sql , 'INSERT INTO `table``name` VALUES (1)' ) ;
576+ } ) ;
577+
578+ test ( 'multiple backtick identifiers with mixed comment markers' , ( ) => {
579+ const sql = format (
580+ 'SELECT * FROM `db--1`.`table/*test*/` WHERE `col--id` = ?' ,
581+ [ 42 ]
582+ ) ;
583+ assert . equal (
584+ sql ,
585+ 'SELECT * FROM `db--1`.`table/*test*/` WHERE `col--id` = 42'
586+ ) ;
587+ } ) ;
588+
589+ test ( 'UPDATE with backtick identifiers containing dashes' , ( ) => {
590+ const sql = format ( 'UPDATE `table--name` SET `col--1` = ? WHERE id = ?' , [
591+ 'value' ,
592+ 1 ,
593+ ] ) ;
594+ assert . equal (
595+ sql ,
596+ "UPDATE `table--name` SET `col--1` = 'value' WHERE id = 1"
597+ ) ;
598+ } ) ;
599+
600+ test ( 'SELECT with ?? and backtick-quoted values with dashes' , ( ) => {
601+ const sql = format ( 'SELECT ?? FROM `users--table` WHERE id = ?' , [
602+ [ 'col--1' , 'col--2' ] ,
603+ 1 ,
604+ ] ) ;
605+ assert . equal (
606+ sql ,
607+ 'SELECT `col--1`, `col--2` FROM `users--table` WHERE id = 1'
608+ ) ;
609+ } ) ;
610+
611+ test ( 'SELECT with ?? without any backticks in query' , ( ) => {
612+ const sql = format ( 'SELECT ?? FROM users WHERE id = ?' , [
613+ [ 'id' , 'name' ] ,
614+ 1 ,
615+ ] ) ;
616+ assert . equal ( sql , 'SELECT `id`, `name` FROM users WHERE id = 1' ) ;
617+ } ) ;
618+ } ) ;
0 commit comments