Skip to content

Commit dccc4e1

Browse files
committed
Fix bug introduced when removing brace escaping
Fixes #4.
1 parent 8ed5e11 commit dccc4e1

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Fixed bug introduced when removing brace escaping support that lead to out-of-bound panics when two bound parameter references were too far apart. ([#4](https://github.com/kyrias/sqlx-conditional-queries/issues/4))

core/src/expand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ fn expand_compile_time_bindings(
174174
let mut fragment_str = fragment_string.as_str();
175175

176176
while let Some(start_of_binding) = fragment_str.find('{') {
177-
// Otherwise we've hit either a compile-time or a run-time binding, so first we
178-
// push any prefix before the binding.
177+
// We've hit either a compile-time or a run-time binding, so first we push any prefix
178+
// before the binding.
179179
if !fragment_str[..start_of_binding].is_empty() {
180180
expanded_fragments.push(syn::LitStr::new(
181181
&fragment_str[..start_of_binding],
@@ -191,7 +191,7 @@ fn expand_compile_time_bindings(
191191
return Err(ExpandError::MissingBindingClosingBrace(fragment.span()));
192192
};
193193

194-
if fragment_str[start_of_binding..].chars().nth(1) == Some('#') {
194+
if fragment_str.chars().nth(1) == Some('#') {
195195
// If the binding is a compile-time binding, expand it.
196196
let binding_name = &fragment_str[2..end_of_binding];
197197
if let Some(binding) = compile_time_bindings.get(binding_name) {

core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod regressions;

core/tests/regressions/issue_4.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[test]
2+
fn regression_test_() {
3+
let input: proc_macro2::TokenStream = r##"
4+
SomeType,
5+
r#"{#a}______{c}"#,
6+
#a = match _ {
7+
_ => "b",
8+
},
9+
"##
10+
.parse()
11+
.unwrap();
12+
13+
sqlx_conditional_queries_core::conditional_query_as(input).unwrap();
14+
}

core/tests/regressions/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod issue_4;

0 commit comments

Comments
 (0)