Skip to content

Commit 95083fd

Browse files
committed
Migrate to snakeyaml-engine
1 parent a0d183b commit 95083fd

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.github/CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Contributing
22

33
## Commit messages
4+
45
Before writing a commit message read [this article](https://chris.beams.io/posts/git-commit/).
56

67
## Build
8+
79
Before pushing any changes make sure project builds without errors with:
810
`./gradlew build`
911

1012
## Unit tests
13+
1114
This project uses [Spock](https://spockframework.org) for testing.
1215
Please use the `Spec.groovy` suffix on new test classes.
1316

1417
Pull requests that lower test coverage will not be merged.
1518
Test coverage metric will be visible on GitHub Pull request page.
1619
It can be also generated in IDE or via command line with `./gradlew build coverage`
20+
1721
- check html report in `build/report/jacoco/coverage/html`.
1822

1923
## Validate changes locally
24+
2025
Before submitting a pull request test your changes locally on a sample project.
2126
There are few ways for local testing:
2227

@@ -25,6 +30,7 @@ There are few ways for local testing:
2530
via [`mavenLocal()`](https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:maven_local) repository
2631

2732
## Validating with snapshot release
33+
2834
Snapshot release is triggered automatically after merge to the main branch.
2935
To use a released snapshot version make sure to register Sonatype snapshot repository in gradle with:
3036

@@ -40,6 +46,12 @@ repositories {
4046

4147
The snapshot version can be found in GitHub Action build log.
4248

49+
## Formatting
50+
51+
There are no enforced code style rules for Java and Groovy sources.
52+
Just please use IntelliJ code styles from "Project scheme" (`.idea/codeStyles`).
53+
4354
## Documentation
55+
4456
If change adds new feature or modifies a new one
4557
update [documentation](https://github.com/coditory/quark-i18n/tree/master/samples).

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ groovy = { module = "org.apache.groovy:groovy", version.ref = "groovy" }
1313
# dependencies
1414
slf4j-api = { module = "org.slf4j:slf4j-api", version = "2.0.11" }
1515
jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.1.0" }
16-
snakeyaml = { module = "org.yaml:snakeyaml", version = "2.1" }
16+
snakeyaml = { module = "org.snakeyaml:snakeyaml-engine", version = "2.7" }
1717
gson = { module = "com.google.code.gson:gson", version = "2.10.1" }
1818
jimfs = { module = "com.google.jimfs:jimfs", version = "1.3.0" }
1919
icu4j = { module = "com.ibm.icu:icu4j", version = "74.2" }

src/main/java/com/coditory/quark/i18n/parser/YamlI18nParser.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import com.coditory.quark.i18n.I18nKey;
44
import org.jetbrains.annotations.NotNull;
55
import org.jetbrains.annotations.Nullable;
6-
import org.yaml.snakeyaml.Yaml;
6+
import org.snakeyaml.engine.v2.api.Load;
7+
import org.snakeyaml.engine.v2.api.LoadSettings;
78

89
import java.util.Locale;
910
import java.util.Map;
@@ -19,11 +20,12 @@ public Map<I18nKey, String> parse(@NotNull String content, @Nullable Locale loca
1920
return I18nParsers.parseEntries(entries, locale);
2021
}
2122

23+
@SuppressWarnings("unchecked")
2224
private Map<String, Object> parseYaml(@NotNull String content) {
2325
try {
24-
Yaml yaml = new Yaml(); // Yaml is not thread safe!
25-
Map<String, Object> entries = yaml.load(content);
26-
return entries == null || entries.isEmpty() ? Map.of() : entries;
26+
LoadSettings settings = LoadSettings.builder().build();
27+
Load yaml = new Load(settings);
28+
return (Map<String, Object>) yaml.loadFromString(content);
2729
} catch (Throwable e) {
2830
throw new I18nParseException("Could not parse YAML", e);
2931
}

0 commit comments

Comments
 (0)