Skip to content

Commit

Permalink
[JENKINS-39062] Sanitise data
Browse files Browse the repository at this point in the history
- Also add equals/hashCode/toString
  • Loading branch information
stephenc committed Oct 18, 2016
1 parent e09c6e0 commit 0b13cf6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 6 deletions.
Expand Up @@ -24,10 +24,13 @@

package org.jenkinsci.plugins.github_branch_source;

import hudson.Util;
import hudson.model.InvisibleAction;
import java.io.IOException;
import java.io.ObjectStreamException;
import java.net.URL;
import jenkins.branch.OrganizationFolder;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.github.GHUser;

/**
Expand All @@ -47,23 +50,69 @@ public GitHubOrgAction(GHUser org) throws IOException {

public GitHubOrgAction(URL url, String name, String avatar) {
this.url = url;
this.name = name;
this.avatar = avatar;
this.name = Util.fixEmpty(name);
this.avatar = Util.fixEmpty(avatar);
}

public GitHubOrgAction(GitHubOrgAction that) {
this(that.getUrl(), that.getName(), that.getAvatar());
}

private Object readResolve() throws ObjectStreamException {
if ((name != null && StringUtils.isBlank(name))
|| (avatar != null && StringUtils.isBlank(avatar)))
return new GitHubOrgAction(this);
return this;
}

public URL getUrl() {
return url;
}

public String getName() {
return name;
return Util.fixEmpty(name);
}

public String getAvatar() {
return avatar;
return Util.fixEmpty(avatar);
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

GitHubOrgAction that = (GitHubOrgAction) o;

return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getUrl() != null ? getUrl().hashCode() : 0;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "GitHubOrgAction{" +
"url=" + url +
", name='" + name + '\'' +
", avatar='" + avatar + '\'' +
"}";
}


}
Expand Up @@ -24,9 +24,12 @@

package org.jenkinsci.plugins.github_branch_source;

import hudson.Util;
import hudson.model.InvisibleAction;
import java.io.ObjectStreamException;
import java.net.URL;
import jenkins.branch.MultiBranchProject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.github.GHRepository;

/**
Expand All @@ -46,14 +49,21 @@ public GitHubRepoAction(GHRepository repo) {

public GitHubRepoAction(URL url, String description, String homepage) {
this.url = url;
this.description = description;
this.homepage = homepage;
this.description = Util.fixEmpty(description);
this.homepage = Util.fixEmpty(homepage);
}

public GitHubRepoAction(GitHubRepoAction that) {
this(that.getUrl(), that.getDescription(), that.getHomepage());
}

private Object readResolve() throws ObjectStreamException {
if ((description != null && StringUtils.isBlank(description))
|| (homepage != null && StringUtils.isBlank(homepage)))
return new GitHubRepoAction(this);
return this;
}

public URL getUrl() {
return url;
}
Expand All @@ -65,4 +75,42 @@ public String getDescription() {
public String getHomepage() {
return homepage;
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

GitHubRepoAction that = (GitHubRepoAction) o;

return getUrl() != null ? getUrl().equals(that.getUrl()) : that.getUrl() == null;

}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return getUrl() != null ? getUrl().hashCode() : 0;
}

/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "GitHubRepoAction{" +
"url=" + url +
", description='" + description + '\'' +
", homepage='" + homepage + '\'' +
"}";
}
}

0 comments on commit 0b13cf6

Please sign in to comment.