@@ -93,9 +93,9 @@ public function getString(): string
9393 */
9494 public function render (OutputFormat $ outputFormat ): string
9595 {
96- $ string = $ this -> escape ( $ this -> string , $ outputFormat ->getStringQuotingType ());
97- $ string = \str_replace ( "\n" , '\\ A ' , $ string);
98- return $ outputFormat -> getStringQuotingType () . $ string . $ outputFormat ->getStringQuotingType ();
96+ return $ outputFormat ->getStringQuotingType ()
97+ . $ this -> escape ( $ this -> string , $ outputFormat )
98+ . $ outputFormat ->getStringQuotingType ();
9999 }
100100
101101 /**
@@ -112,14 +112,14 @@ public function getArrayRepresentation(): array
112112 ];
113113 }
114114
115- /**
116- * @param "'"|'"' $quote
117- */
118- private function escape (string $ string , string $ quote ): string
115+ private function escape (string $ string , OutputFormat $ outputFormat ): string
119116 {
120117 $ charactersToEscape = '\\' ;
121- $ charactersToEscape .= ($ quote === '" ' ? '" ' : "' " );
118+ $ charactersToEscape .= ($ outputFormat ->getStringQuotingType () === '" ' ? '" ' : "' " );
119+ $ withEscapedQuotes = \addcslashes ($ string , $ charactersToEscape );
120+
121+ $ withNewlineEncoded = \str_replace ("\n" , '\\A ' , $ withEscapedQuotes );
122122
123- return \addcslashes ( $ string , $ charactersToEscape ) ;
123+ return $ withNewlineEncoded ;
124124 }
125125}
0 commit comments