Skip to content

Commit 1651fcc

Browse files
committed
Fix bug with multiple var refs in quoted strings/identifiers.
- Fix incorrect result or index-out-of-range exception when multiple variable replacements occur in a quoted string or in a quoted identifier.
1 parent db5f7c6 commit 1651fcc

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Most lines should begin with one of these words:
1010
-->
1111

1212
## [1.0.2](https://github.com/sharpjs/Prequel/compare/release/1.0.1..release/1.0.2)
13+
- Fix incorrect result or index-out-of-range exception when multiple variable
14+
replacements occur in a quoted string or in a quoted identifier.
1315

1416
## [1.0.1](https://github.com/sharpjs/Prequel/compare/release/1.0.0..release/1.0.1)
1517
- Fix missing IntelliSense.

Prequel.Tests/SqlCmdPreprocessorTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ public void Process_VariableReplacement_Normal(string eol, string eof)
224224
};
225225

226226
var batches = preprocessor.Process(
227-
Lines(eol, eof, "a $(FOO) b")
227+
Lines(eol, eof, "a $(FOO) b $(foo) c")
228228
);
229229

230230
batches.Should().Equal(
231-
Lines(eol, eof, "a bar b")
231+
Lines(eol, eof, "a bar b bar c")
232232
);
233233
}
234234

@@ -285,11 +285,11 @@ public void Process_VariableReplacement_InSingleQuotedString(string eol, string
285285
};
286286

287287
var batches = preprocessor.Process(
288-
Lines(eol, eof, "a 'b '' $(fOO) c' d")
288+
Lines(eol, eof, "a 'b '' $(fOO) $(Foo) c' d")
289289
);
290290

291291
batches.Should().Equal(
292-
Lines(eol, eof, "a 'b '' bar c' d")
292+
Lines(eol, eof, "a 'b '' bar bar c' d")
293293
);
294294
}
295295

@@ -303,11 +303,11 @@ public void Process_VariableReplacement_InBracketQuotedIdentifier(string eol, st
303303
};
304304

305305
var batches = preprocessor.Process(
306-
Lines(eol, eof, "a [b ]] $(fOo) c] d")
306+
Lines(eol, eof, "a [b ]] $(fOo) $(foO) c] d")
307307
);
308308

309309
batches.Should().Equal(
310-
Lines(eol, eof, "a [b ]] bar c] d")
310+
Lines(eol, eof, "a [b ]] bar bar c] d")
311311
);
312312
}
313313

Prequel/SqlCmdPreprocessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ private void PerformVariableReplacement(StringBuilder builder, string text)
350350
return;
351351
}
352352

353-
builder.Append(text, start, match.Index);
353+
builder.Append(text, start, match.Index - start);
354354
builder.Append(GetVariableReplacement(match));
355355

356356
start = match.Index + match.Length;

0 commit comments

Comments
 (0)