@@ -775,16 +775,24 @@ pub(crate) fn ascii_attribute_markup(markup: String) -> String {
775775 if is_one_byte ( & markup) {
776776 return markup;
777777 }
778- ascii_parts ( & [ markup] , AsciiState :: Tag { raw : None } )
779- . pop ( )
780- . unwrap_or_default ( )
778+ ascii_parts (
779+ & [ markup] ,
780+ AsciiState :: Tag {
781+ raw : None ,
782+ value : false ,
783+ } ,
784+ )
785+ . pop ( )
786+ . unwrap_or_default ( )
781787}
782788
783789#[ derive( Clone , Copy , PartialEq ) ]
784790enum AsciiState {
785791 Text ,
786792 Tag {
787793 raw : Option < & ' static str > ,
794+ // Only a quote right after `=` opens a quoted value.
795+ value : bool ,
788796 } ,
789797 Quoted {
790798 quote : char ,
@@ -809,6 +817,8 @@ pub(crate) fn raw_text_close(name: &str) -> Option<&'static str> {
809817 "noembed" => Some ( "</noembed" ) ,
810818 "noframes" => Some ( "</noframes" ) ,
811819 "xmp" => Some ( "</xmp" ) ,
820+ // `<plaintext>` has no end tag.
821+ "plaintext" => Some ( "" ) ,
812822 _ => None ,
813823 }
814824}
@@ -855,6 +865,7 @@ fn ascii_parts(parts: &[String], mut state: AsciiState) -> std::vec::Vec<String>
855865 . to_ascii_lowercase ( ) ;
856866 state = AsciiState :: Tag {
857867 raw : if closing { None } else { raw_text_close ( & name) } ,
868+ value : false ,
858869 } ;
859870 } else if closing {
860871 state = AsciiState :: Preserve ( ">" ) ;
@@ -867,20 +878,24 @@ fn ascii_parts(parts: &[String], mut state: AsciiState) -> std::vec::Vec<String>
867878 out. push_str ( & rest[ ..len] ) ;
868879 }
869880 }
870- AsciiState :: Tag { raw } => {
871- if ch == '"' || ch == '\'' {
881+ AsciiState :: Tag { raw, value } => {
882+ if value && ( ch == '"' || ch == '\'' ) {
872883 state = AsciiState :: Quoted { quote : ch, raw } ;
873884 } else if ch == '>' {
874885 state = raw. map_or ( AsciiState :: Text , |close| AsciiState :: Raw {
875886 close,
876887 escaped : false ,
877888 } ) ;
889+ } else if ch == '=' || ( value && ch. is_ascii_whitespace ( ) ) {
890+ state = AsciiState :: Tag { raw, value : true } ;
891+ } else {
892+ state = AsciiState :: Tag { raw, value : false } ;
878893 }
879894 out. push ( ch) ;
880895 }
881896 AsciiState :: Quoted { quote, raw } => {
882897 if ch == quote {
883- state = AsciiState :: Tag { raw } ;
898+ state = AsciiState :: Tag { raw, value : false } ;
884899 }
885900 push_ascii ( & mut out, ch) ;
886901 }
@@ -898,11 +913,15 @@ fn ascii_parts(parts: &[String], mut state: AsciiState) -> std::vec::Vec<String>
898913 escaped : true ,
899914 } ;
900915 } else if !escaped
916+ && !close. is_empty ( )
901917 && rest. len ( ) >= close. len ( )
902918 && rest. as_bytes ( ) [ ..close. len ( ) ] . eq_ignore_ascii_case ( close. as_bytes ( ) )
903919 && ends_tag_name ( rest[ close. len ( ) ..] . chars ( ) . next ( ) )
904920 {
905- state = AsciiState :: Tag { raw : None } ;
921+ state = AsciiState :: Tag {
922+ raw : None ,
923+ value : false ,
924+ } ;
906925 }
907926 out. push ( ch) ;
908927 }
@@ -1025,6 +1044,22 @@ mod ascii_template_tests {
10251044 ) ;
10261045 }
10271046
1047+ #[ test]
1048+ fn quote_opens_a_value_only_after_equals ( ) {
1049+ assert_eq ! (
1050+ run( & [ "<style data-x=a'b>.a::after{content:\" →\" }</style><p title = '→'>→" ] ) ,
1051+ [ "<style data-x=a'b>.a::after{content:\" →\" }</style><p title = '→'>→" ]
1052+ ) ;
1053+ }
1054+
1055+ #[ test]
1056+ fn plaintext_stays_raw_to_the_end ( ) {
1057+ assert_eq ! (
1058+ run( & [ "<p>→</p><plaintext><p>→</p></plaintext>→" ] ) ,
1059+ [ "<p>→</p><plaintext><p>→</p></plaintext>→" ]
1060+ ) ;
1061+ }
1062+
10281063 #[ test]
10291064 fn astral_characters_use_one_reference ( ) {
10301065 assert_eq ! ( run( & [ "<p>😀</p>" ] ) , [ "<p>😀</p>" ] ) ;
0 commit comments