Skip to content

ConfigurationPropertyName#equals is not symmetric when adapt has removed trailing characters from an element #30317

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

Closed
Adams112 opened this issue Mar 18, 2022 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@Adams112
Copy link

Use ConfigurationPropertyName#adapt method to create two ConfigurationPropertyName, a equals to b but b not equals to a

boolean c1 = adapt("demo", '.').equals(adapt("demo$$", '.'));  // true
boolean c2 = adapt("demo$$", '.').equals(adapt("demo", '.'));  // false

The problems is in defaultElementEquals method, see below

private boolean defaultElementEquals(Elements e1, Elements e2, int i) {
		int l1 = e1.getLength(i);
		int l2 = e2.getLength(i);
		boolean indexed1 = e1.getType(i).isIndexed();
		boolean indexed2 = e2.getType(i).isIndexed();
		int i1 = 0;
		int i2 = 0;
		while (i1 < l1) {
                        // at this point, e1 has extra invalid chars, but e2 is end, returned false without cheking
                        // left chars of e1
			if (i2 >= l2) {
				return false;
			}
			char ch1 = indexed1 ? e1.charAt(i, i1) : Character.toLowerCase(e1.charAt(i, i1));
			char ch2 = indexed2 ? e2.charAt(i, i2) : Character.toLowerCase(e2.charAt(i, i2));
			if (!indexed1 && !ElementsParser.isAlphaNumeric(ch1)) {
				i1++;
			}
			else if (!indexed2 && !ElementsParser.isAlphaNumeric(ch2)) {
				i2++;
			}
			else if (ch1 != ch2) {
				return false;
			}
			else {
				i1++;
				i2++;
			}
		}
		if (i2 < l2) {
			if (indexed2) {
				return false;
			}
			do {
				char ch2 = Character.toLowerCase(e2.charAt(i, i2++));
				if (ElementsParser.isAlphaNumeric(ch2)) {
					return false;
				}
			}
			while (i2 < l2);
		}
		return true;
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 18, 2022
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 23, 2022
@wilkinsona wilkinsona added this to the 2.5.x milestone Mar 23, 2022
@wilkinsona wilkinsona changed the title ConfigurationPropertyName#equals method has Unexpected characteristic ConfigurationPropertyName#equals is not symmetric for adapted names Mar 23, 2022
@wilkinsona wilkinsona changed the title ConfigurationPropertyName#equals is not symmetric for adapted names ConfigurationPropertyName#equals is not symmetric when adapt has removed trailing characters from an element Mar 23, 2022
@wilkinsona wilkinsona self-assigned this Mar 23, 2022
@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.11 Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants