File tree Expand file tree Collapse file tree
lib/cli-engine/formatters
tests/lib/cli-engine/formatters Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -244,7 +244,7 @@ function messageTemplate(it) {
244244 <td class="clr-${ severityNumber } ">${ severityName } </td>
245245 <td>${ encodeHTML ( message ) } </td>
246246 <td>
247- <a href="${ ruleUrl ? ruleUrl : "" } " target="_blank" rel="noopener noreferrer">${ ruleId ? ruleId : "" } </a>
247+ <a href="${ ruleUrl ? ruleUrl : "" } " target="_blank" rel="noopener noreferrer">${ encodeHTML ( ruleId ) } </a>
248248 </td>
249249</tr>
250250` . trimStart ( ) ;
Original file line number Diff line number Diff line change @@ -792,6 +792,58 @@ describe("formatter:html", () => {
792792 } ) ;
793793 } ) ;
794794
795+ describe ( "when passing a single message with special characters in the rule id" , ( ) => {
796+ const rulesMeta = {
797+ "<&>" : {
798+ type : "problem" ,
799+
800+ docs : {
801+ description :
802+ "This is a rule with special characters in its id" ,
803+ recommended : true ,
804+ url : "https://example.com/some-rule" ,
805+ } ,
806+
807+ fixable : "code" ,
808+
809+ messages : {
810+ message1 : "This is a message for rule '<&>'." ,
811+ } ,
812+ } ,
813+ } ;
814+ const code = {
815+ results : [
816+ {
817+ filePath : "foo.js" ,
818+ errorCount : 1 ,
819+ warningCount : 0 ,
820+ messages : [
821+ {
822+ message : "Unexpected foo." ,
823+ severity : 2 ,
824+ line : 5 ,
825+ column : 10 ,
826+ ruleId : "<&>" ,
827+ source : "foo" ,
828+ } ,
829+ ] ,
830+ } ,
831+ ] ,
832+ rulesMeta,
833+ } ;
834+
835+ it ( "should escape the rule id" , ( ) => {
836+ const result = formatter ( code . results , { rulesMeta } ) ;
837+ const $ = cheerio . load ( result ) ;
838+
839+ assert . strictEqual (
840+ $ ( "td" ) . eq ( 3 ) . html ( ) . trim ( ) ,
841+ '<a href="https://example.com/some-rule" target="_blank" rel="noopener noreferrer"><&></a>' ,
842+ "Check that rule id is escaped correctly" ,
843+ ) ;
844+ } ) ;
845+ } ) ;
846+
795847 describe ( "when passing a single message with no rule id or message" , ( ) => {
796848 const code = [
797849 {
You can’t perform that action at this time.
0 commit comments