@@ -51,6 +51,58 @@ describe("composer rich text markdown", () => {
5151 ] ) ;
5252 } ) ;
5353
54+ // regression: #25180 underscores in URLs and paths were read as emphasis
55+ it ( "keeps underscores inside URLs, paths, and filenames literal" , ( ) => {
56+ for ( const text of [
57+ "Read https://example.com/_handle_/status/1 and open src/__test__.tsx" ,
58+ "https://example.com/~_user_/a" ,
59+ "_build_/file.ts" ,
60+ "edit __init__.py, then" ,
61+ "see __init__.py:42" ,
62+ "open src/_a.ts_ and example.com/_handle_." ,
63+ "/" + "_" . repeat ( 50_000 ) + "a" ,
64+ ] ) {
65+ expect ( parseInlineMarkdown ( text ) ) . toEqual ( [ { text, marks : [ ] } ] ) ;
66+ }
67+ for ( const [ text , styled , mark , rest ] of [
68+ [ "_see src/a_b.ts_ now" , "see src/a_b.ts" , "italic" , " now" ] ,
69+ [ "_read/write access_ now" , "read/write access" , "italic" , " now" ] ,
70+ [ "__read/write access__ now" , "read/write access" , "bold" , " now" ] ,
71+ [ "_see src/_a.ts_(optional)" , "see src/_a.ts" , "italic" , "(optional)" ] ,
72+ [ "__see src/__a.ts__(optional)" , "see src/__a.ts" , "bold" , "(optional)" ] ,
73+ [ "_see src/_a.ts_." , "see src/_a.ts" , "italic" , "." ] ,
74+ [ "_notes.md_ here" , "notes.md" , "italic" , " here" ] ,
75+ [ "_e.g._ this" , "e.g." , "italic" , " this" ] ,
76+ [ "_and_/or" , "and" , "italic" , "/or" ] ,
77+ ] as const ) {
78+ expect ( parseInlineMarkdown ( text ) ) . toEqual ( [
79+ { text : styled , marks : [ mark ] } ,
80+ { text : rest , marks : [ ] } ,
81+ ] ) ;
82+ }
83+ for ( const [ text , first , second , mark ] of [
84+ [ "_yes_/_no_" , "yes" , "no" , "italic" ] ,
85+ [ "__yes__/__no__." , "yes" , "no" , "bold" ] ,
86+ [ "_a_b_/_no_" , "a_b" , "no" , "italic" ] ,
87+ ] as const ) {
88+ expect ( parseInlineMarkdown ( text ) . slice ( 0 , 3 ) ) . toEqual ( [
89+ { text : first , marks : [ mark ] } ,
90+ { text : "/" , marks : [ ] } ,
91+ { text : second , marks : [ mark ] } ,
92+ ] ) ;
93+ }
94+ expect ( parseInlineMarkdown ( "and/_or_" ) ) . toEqual ( [
95+ { text : "and/" , marks : [ ] } ,
96+ { text : "or" , marks : [ "italic" ] } ,
97+ ] ) ;
98+ expect ( parseInlineMarkdown ( "_build_/file.ts and _x_, __init__.py and __y__" ) ) . toEqual ( [
99+ { text : "_build_/file.ts and " , marks : [ ] } ,
100+ { text : "x" , marks : [ "italic" ] } ,
101+ { text : ", __init__.py and " , marks : [ ] } ,
102+ { text : "y" , marks : [ "bold" ] } ,
103+ ] ) ;
104+ } ) ;
105+
54106 it ( "keeps code span contents literal" , ( ) => {
55107 expect ( parseInlineMarkdown ( "`**not bold**`" ) ) . toEqual ( [
56108 { text : "**not bold**" , marks : [ "code" ] } ,
0 commit comments