File tree Expand file tree Collapse file tree
packages/shared/kbn-monaco/src/languages/console
plugins/shared/console/public/application/hooks/use_send_current_request Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -195,4 +195,27 @@ describe('console parser', () => {
195195 { startOffset : 22 , endOffset : 32 } ,
196196 ] ) ;
197197 } ) ;
198+
199+ describe ( 'CRLF line endings (Windows)' , ( ) => {
200+ it ( 'parses a single request with CRLF line endings without errors' , ( ) => {
201+ const input = 'GET _search\r\n' ;
202+ const { requests, errors } = parser ( input ) ! ;
203+ expect ( errors ) . toEqual ( [ ] ) ;
204+ expect ( requests . length ) . toBe ( 1 ) ;
205+ } ) ;
206+
207+ it ( 'parses a bulk request with CRLF line endings without errors' , ( ) => {
208+ const input = 'POST /_bulk\r\n{"create": {}}\r\n{"field": "value"}\r\n' ;
209+ const { requests, errors } = parser ( input ) ! ;
210+ expect ( errors ) . toEqual ( [ ] ) ;
211+ expect ( requests . length ) . toBe ( 1 ) ;
212+ } ) ;
213+
214+ it ( 'parses multiple requests separated by CRLF without errors' , ( ) => {
215+ const input = 'GET _search\r\nPOST _test_index\r\n' ;
216+ const { requests, errors } = parser ( input ) ! ;
217+ expect ( errors ) . toEqual ( [ ] ) ;
218+ expect ( requests . length ) . toBe ( 2 ) ;
219+ } ) ;
220+ } ) ;
198221} ) ;
Original file line number Diff line number Diff line change @@ -207,6 +207,7 @@ export const createParser = (): ConsoleParser => {
207207 }
208208 } ;
209209 const newLine = function ( ) {
210+ if ( ch === '\r' ) ch = next ( ) ; // handle CRLF: skip \r before \n
210211 if ( ch === '\n' ) ch = next ( ) ;
211212 } ;
212213 const word = function ( ) {
@@ -355,7 +356,7 @@ export const createParser = (): ConsoleParser => {
355356
356357 const url = function ( ) {
357358 let parsedUrl = '' ;
358- while ( ch && ch !== '\n' ) {
359+ while ( ch && ch !== '\n' && ch !== '\r' ) {
359360 parsedUrl += ch ;
360361 next ( ) ;
361362 }
Original file line number Diff line number Diff line change @@ -101,7 +101,7 @@ export function sendRequest(args: RequestArgs): Promise<RequestResult[]> {
101101 // If the request data contains multiple data objects (e.g. bulk request)
102102 // ES only accepts it if each object is on a single line
103103 // Therefore, we need to remove all new line characters from each data object
104- const unformattedData = req . data . map ( ( body ) => body . replaceAll ( '\n' , '' ) ) ;
104+ const unformattedData = req . data . map ( ( body ) => body . replace ( / [ \r \n ] / g , '' ) ) ;
105105
106106 let data = collapseLiteralStrings ( unformattedData . join ( '\n' ) ) ;
107107 if ( data ) {
You can’t perform that action at this time.
0 commit comments