mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 13:07:47 +00:00
fix: use utf-8 length instead of byte length
This commit is contained in:
parent
8213b1fecb
commit
08627c847e
4 changed files with 23 additions and 3 deletions
12
CHANGELOG.md
12
CHANGELOG.md
|
@ -17,6 +17,18 @@ Types of changes
|
||||||
- Security in case of vulnerabilities.
|
- Security in case of vulnerabilities.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Multiline strings are handled as utf-8 correctly, preventing panics
|
||||||
|
on utf-8 whitespace like:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
\u{2002}bar
|
||||||
|
''
|
||||||
|
```
|
||||||
|
|
||||||
## [0.5.0] - 2022-02-23
|
## [0.5.0] - 2022-02-23
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub fn rule(
|
||||||
if !line.is_empty() {
|
if !line.is_empty() {
|
||||||
indentation = usize::min(
|
indentation = usize::min(
|
||||||
indentation,
|
indentation,
|
||||||
line.len() - line.trim_start().len(),
|
line.chars().count() - line.trim_start().chars().count(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,8 @@ pub fn rule(
|
||||||
lines = lines
|
lines = lines
|
||||||
.iter()
|
.iter()
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
if indentation < line.len() {
|
if indentation < line.chars().count() {
|
||||||
line[indentation..line.len()].to_string()
|
line.chars().skip(indentation).collect::<String>()
|
||||||
} else {
|
} else {
|
||||||
line.to_string()
|
line.to_string()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
[
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
""
|
""
|
||||||
###
|
###
|
||||||
"
|
"
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
[
|
[
|
||||||
|
''
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
''
|
||||||
""
|
""
|
||||||
###
|
###
|
||||||
"
|
"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue