File tree Expand file tree Collapse file tree 2 files changed +36
-17
lines changed Expand file tree Collapse file tree 2 files changed +36
-17
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,23 @@ func blockStringValue(in string) string {
381
381
// Expand a block string's raw value into independent lines.
382
382
lines := splitLinesRegex .Split (in , - 1 )
383
383
384
+ // Remove leading blank lines.
385
+ for {
386
+ if isBlank := lineIsBlank (lines [0 ]); ! isBlank {
387
+ break
388
+ }
389
+ lines = lines [1 :]
390
+ }
391
+
392
+ // Remove trailing blank lines.
393
+ for {
394
+ i := len (lines ) - 1
395
+ if isBlank := lineIsBlank (lines [i ]); ! isBlank {
396
+ break
397
+ }
398
+ lines = append (lines [:i ], lines [i + 1 :]... )
399
+ }
400
+
384
401
// Remove common indentation from all lines but first
385
402
commonIndent := - 1
386
403
for i := 1 ; i < len (lines ); i ++ {
@@ -395,27 +412,13 @@ func blockStringValue(in string) string {
395
412
}
396
413
if commonIndent > 0 {
397
414
for i , line := range lines {
415
+ if commonIndent > len (line ) {
416
+ continue
417
+ }
398
418
lines [i ] = line [commonIndent :]
399
419
}
400
420
}
401
421
402
- // Remove leading blank lines.
403
- for {
404
- if isBlank := lineIsBlank (lines [0 ]); ! isBlank {
405
- break
406
- }
407
- lines = lines [1 :]
408
- }
409
-
410
- // Remove trailing blank lines.
411
- for {
412
- i := len (lines ) - 1
413
- if isBlank := lineIsBlank (lines [i ]); ! isBlank {
414
- break
415
- }
416
- lines = append (lines [:i ], lines [i + 1 :]... )
417
- }
418
-
419
422
// Return a string of the lines joined with U+000A.
420
423
return strings .Join (lines , "\n " )
421
424
}
Original file line number Diff line number Diff line change @@ -480,6 +480,22 @@ func TestLexer_LexesBlockStrings(t *testing.T) {
480
480
Value : " white space " ,
481
481
},
482
482
},
483
+ {
484
+ Body : `
485
+ """
486
+ my great description
487
+ spans multiple lines
488
+
489
+ with breaks
490
+ """
491
+ ` ,
492
+ Expected : Token {
493
+ Kind : TokenKind [BLOCK_STRING ],
494
+ Start : 5 ,
495
+ End : 89 ,
496
+ Value : "my great description\n spans multiple lines\n \n with breaks" ,
497
+ },
498
+ },
483
499
{
484
500
Body : `"""contains " quote"""` ,
485
501
Expected : Token {
You can’t perform that action at this time.
0 commit comments