-
Notifications
You must be signed in to change notification settings - Fork 89
IDETECT-5134 : fix(pnpm): use UTF-8 encoding when reading pnpm-lock.yaml to handle emojis and non-ASCII characters #1793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1d4b021
fix: read pnpm-lock.yaml as UTF-8 to handle emojis and non-ASCII chars
bd-spratikbharti 149dadd
Release 12.0.0-SIGQA3-IDETECT-5134
2162d4c
Using the next snapshot post release 12.0.0-SIGQA4-IDETECT-5134-SNAPSHOT
afadcd0
Use try-with-resources to gurantee proper close() and prevent file de…
bd-spratikbharti 083a547
Added unit tests for emoji and non-ASCII characters in pnpm
bd-spratikbharti b915008
Merge branch 'master' into IDETECT-5134
bd-spratikbharti ff5ef95
Merge branch 'master' into IDETECT-5134
bd-spratikbharti 889e90a
Fixed merge conflict
bd-spratikbharti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...om/blackduck/integration/detectable/detectables/pnpm/unit/PnpmLockYamlParserUtf8Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.blackduck.integration.detectable.detectables.pnpm.unit; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.blackduck.integration.detectable.detectable.codelocation.CodeLocation; | ||
| import com.blackduck.integration.detectable.detectable.util.EnumListFilter; | ||
| import com.blackduck.integration.detectable.detectables.pnpm.lockfile.PnpmLockOptions; | ||
| import com.blackduck.integration.detectable.detectables.pnpm.lockfile.model.PnpmDependencyType; | ||
| import com.blackduck.integration.detectable.detectables.pnpm.lockfile.process.PnpmLinkedPackageResolver; | ||
| import com.blackduck.integration.detectable.detectables.pnpm.lockfile.process.PnpmLockYamlParserInitial; | ||
| import com.blackduck.integration.detectable.detectables.yarn.packagejson.PackageJsonFiles; | ||
| import com.blackduck.integration.detectable.detectables.yarn.packagejson.PackageJsonReader; | ||
| import com.blackduck.integration.detectable.util.FunctionalTestFiles; | ||
| import com.blackduck.integration.exception.IntegrationException; | ||
| import com.blackduck.integration.util.NameVersion; | ||
|
|
||
| /** | ||
| * Tests that pnpm-lock.yaml files containing emojis and non-ASCII content | ||
| * are parsed correctly when read with explicit UTF-8 encoding | ||
| * (InputStreamReader + StandardCharsets.UTF_8). | ||
| */ | ||
| public class PnpmLockYamlParserUtf8Test { | ||
|
|
||
| private List<CodeLocation> parseLockFile(String resourcePath) throws IOException, IntegrationException { | ||
| File pnpmLockYaml = FunctionalTestFiles.asFile(resourcePath); | ||
|
|
||
| EnumListFilter<PnpmDependencyType> dependencyTypeFilter = EnumListFilter.excludeNone(); | ||
| PnpmLockOptions pnpmLockOptions = new PnpmLockOptions(dependencyTypeFilter, Collections.emptyList(), Collections.emptyList()); | ||
|
|
||
| PnpmLockYamlParserInitial parser = new PnpmLockYamlParserInitial(pnpmLockOptions); | ||
| PnpmLinkedPackageResolver linkedPackageResolver = new PnpmLinkedPackageResolver( | ||
| pnpmLockYaml.getParentFile(), | ||
| new PackageJsonFiles(new PackageJsonReader(new Gson())) | ||
| ); | ||
|
|
||
| return parser.parse(pnpmLockYaml, new NameVersion("project", "1.0.0"), linkedPackageResolver); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseV9WithEmojiComments() throws IOException, IntegrationException { | ||
| // YAML contains emoji characters (🚀🎉✅❌🔥💡) in comments | ||
| List<CodeLocation> codeLocations = parseLockFile("/pnpm/unicode/v9-emoji-comments/pnpm-lock.yaml"); | ||
|
|
||
| Assertions.assertNotNull(codeLocations, "Code locations should not be null when parsing YAML with emoji comments"); | ||
| Assertions.assertFalse(codeLocations.isEmpty(), "Should produce at least one code location"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParseV5WithAccentedComments() throws IOException, IntegrationException { | ||
| // YAML contains accented (Ünïcödé, Ñoño, résumé, naïveté) and Greek characters in comments | ||
| List<CodeLocation> codeLocations = parseLockFile("/pnpm/unicode/v5-accented/pnpm-lock.yaml"); | ||
|
|
||
| Assertions.assertNotNull(codeLocations, "Code locations should not be null when parsing YAML with accented comments"); | ||
| Assertions.assertFalse(codeLocations.isEmpty(), "Should produce at least one code location"); | ||
| } | ||
|
|
||
| } | ||
|
|
25 changes: 25 additions & 0 deletions
25
detectable/src/test/resources/detectables/functional/pnpm/unicode/v5-accented/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
...e/src/test/resources/detectables/functional/pnpm/unicode/v9-emoji-comments/pnpm-lock.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.