@@ -191,6 +191,55 @@ describe('definitions', () => {
191191 } ) ;
192192} ) ;
193193
194+ describe ( 'CLI help formatting (#8434)' , ( ) => {
195+ const loadInto = defs => {
196+ const command = require ( '../lib/cli/utils/commander' ) . default ;
197+ const program = new command . constructor ( ) ;
198+ program . storeOptionsAsProperties ( ) ;
199+ program . allowExcessArguments ( ) ;
200+ program . loadDefinitions ( defs ) ;
201+ return program ;
202+ } ;
203+ const htmlTag = / < b r \s * \/ ? > | < \/ ? (?: b | u l | l i ) > | < a \b | < \/ a > / i;
204+
205+ it ( 'strips HTML formatting tags from every option description' , ( ) => {
206+ for ( const defs of [ definitions , liveQueryDefinitions ] ) {
207+ loadInto ( defs ) . options . forEach ( option => {
208+ expect ( option . description ) . not . toMatch ( htmlTag ) ;
209+ } ) ;
210+ }
211+ } ) ;
212+
213+ it ( 'converts <br> paragraph breaks to newlines' , ( ) => {
214+ const description = loadInto ( definitions ) . options . find ( o => o . attributeName ( ) === 'directAccess' )
215+ . description ;
216+ expect ( description ) . toContain ( '\n' ) ;
217+ expect ( description ) . not . toContain ( '<br>' ) ;
218+ } ) ;
219+
220+ it ( 'converts <a href> links to "text (url)"' , ( ) => {
221+ const description = loadInto ( definitions ) . options . find ( o => o . attributeName ( ) === 'trustProxy' )
222+ . description ;
223+ expect ( description ) . toContain (
224+ 'express trust proxy settings (https://expressjs.com/en/guide/behind-proxies.html)'
225+ ) ;
226+ } ) ;
227+
228+ it ( 'preserves angle-bracket literals that are not HTML tags' , ( ) => {
229+ // `_auth_data_<provider>` and `<= \`20\`` are literal content, not markup - a blanket strip would eat them.
230+ const program = loadInto ( {
231+ myOption : {
232+ env : 'PARSE_MY_OPTION' ,
233+ help : 'Field `_auth_data_<provider>`.<br>Valid values are >= `0` and <= `20`.' ,
234+ } ,
235+ } ) ;
236+ const description = program . options . find ( o => o . attributeName ( ) === 'myOption' ) . description ;
237+ expect ( description ) . toContain ( '_auth_data_<provider>' ) ;
238+ expect ( description ) . toContain ( '<= `20`' ) ;
239+ expect ( description ) . not . toContain ( '<br>' ) ;
240+ } ) ;
241+ } ) ;
242+
194243describe ( 'LiveQuery definitions' , ( ) => {
195244 it ( 'should have valid types' , ( ) => {
196245 for ( const key in liveQueryDefinitions ) {
0 commit comments