Repository navigation
Fixed security risk and redundant quote #440
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
Changes from 8 commits
7a84260
1cf268a
8c3e1d3
58a1206
f4ef5db
e35347c
e83945c
2a982a8
0d2e0c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,10 +113,12 @@ public String getUser() { | |
|
|
||
| /** | ||
| * Set user value | ||
| * <p> | ||
| * This method's access level is private-package | ||
| * | ||
| * @param user string value | ||
| */ | ||
| public void setUser(String user) { | ||
| void setUser(String user) { | ||
| this.user = user; | ||
| } | ||
|
|
||
|
|
@@ -208,7 +210,18 @@ void setCertPassword(String certPassword) { | |
| * @param basePath string value | ||
| */ | ||
| void setBasePath(String basePath) { | ||
| this.basePath = basePath; | ||
| if (basePath == null || basePath.isBlank()) | ||
| this.basePath = basePath; | ||
| else { | ||
| this.basePath = getNormalizedPath(basePath); | ||
| } | ||
| } | ||
|
|
||
| private String getNormalizedPath(String basePath) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about change this method as follows: /**
* Normalizes a path by collapsing multiple slashes, resolving relative segments (. and ..),
* and ensuring a consistent leading slash. The result is standardized to forward slashes
* and excludes a trailing slash unless it is the root path.
*
* @param basePath The raw path string to normalize.
* @return A canonical Unix-style path string.
*/
private String getNormalizedPath(String basePath) {
// Paths.get handles leading slashes and collapses internal duplicate slashes
// normalize() resolves dot-segments like /./ and /../
final String normalized = Paths.get("/", basePath).normalize().toString().replace("\\", "/");
// Remove trailing slash unless the result is the root "/"
return (normalized.length() > 1 && normalized.endsWith("/"))
? normalized.substring(0, normalized.length() - 1) : normalized;
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can replace all the backward slashes with forward slash in the same logic, but I don't think its a good idea to use "Paths" class as it will interpret "file separator" differently based on OS, for windows and Unix it will be different.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed a new commit to replace backward slashes to forward slashes
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok thanks.. with your updated version and without using Path how about we change the method to be like this way:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually lets change the beginning to this to handle spaces too: |
||
| String normalizedPath = basePath.replace('\\', '/'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do the following here:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant to say: |
||
| normalizedPath = normalizedPath.startsWith("/") ? normalizedPath : "/" + normalizedPath; | ||
| return normalizedPath.endsWith("/") ? | ||
| normalizedPath.substring(0, normalizedPath.length() - 1) : normalizedPath; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -308,10 +321,10 @@ public String toString() { | |
| ", zosmfPort='" + zosmfPort + '\'' + | ||
| ", authType=" + authType + | ||
| ", user='" + user + '\'' + | ||
| ", password='*****'" + '\'' + | ||
| ", token=" + token + | ||
| ", password='*****'" + | ||
| ", token=='*****'" + | ||
| ", certFilePath='" + certFilePath + '\'' + | ||
| ", certPassword='" + certPassword + '\'' + | ||
| ", certPassword=='*****'" + | ||
| ", basePath='" + basePath + '\'' + | ||
| '}'; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,7 +223,7 @@ public void tstUrlConstructionWithoutBasePathSuccess() { | |
| public void tstUrlConstructionWithInvalidBasePathFailure() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test does not consider base path. Tweak is as the following I suggest:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. renamed test |
||
| // Create a connection and set an empty base path | ||
| final ZosConnection connection = ZosConnectionFactory | ||
| .createBasicConnection("test.host", "443", "user", "password", "frank//"); | ||
| .createBasicConnection("test.host:123foo", "443", "user", "password", "frank///"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here we can just use: |
||
| // Create a mock request to verify URL | ||
| final ZosmfRequest request = ZosmfRequestFactory.buildRequest(connection, ZosmfRequestType.GET_JSON); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this method how about we change it too:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like complicated code instead of simple if-else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok never mind.