Skip to content
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

Fix transforming of PathBindable and also the anyValPathBindable macro #11712

Merged
merged 3 commits into from Mar 15, 2023

Conversation

mkurz
Copy link
Member

@mkurz mkurz commented Mar 15, 2023

While working on the macro stuff for Scala 3 I noticed two bugs:

  • When transforming a PathBindable the original javascript unbind method does not get used anymore, which can cause problems for certain types that do not use the default javascript unbind method (e.g. Boolean). All Java types are affected from this "bug", however in real life it should not matter since all use the default method anyway, except boolean, but even for that the default js function should work anyway. It could cause problems for user defind binders however... This has been fixed for the QuerystringBindable long time ago already: Fix bug with javascript unbind and transform #3854
  • The macro code handling AnyVal regarding Pathbindable also does not correctly transform an AnyVal. Even when the above is fixed, the macro does create a new instance which does not override the js method... calling transform is the preferred way here.

The added tests test both scenarios.

@mkurz
Copy link
Member Author

mkurz commented Mar 15, 2023

@Mergifyio backport 2.8.x

@mergify
Copy link
Contributor

mergify bot commented Mar 15, 2023

backport 2.8.x

✅ Backports have been created


override def unbind(key: String, value: ${t.tpe}): String = {
binder.unbind(key, value.${param.name.toTermName})
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The javascriptUnbind does not get overridden.


}
private val binder = _root_.scala.Predef.implicitly[_root_.play.api.mvc.PathBindable[${param.typeSignature}]]
binder.transform((p: ${param.typeSignature}) => new ${t.tpe}(p), (p: ${t.tpe}) => p.${param.name.toTermName})
Copy link
Member Author

@mkurz mkurz Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using transform is preferred, safer and saner. Just like we do below (line 29) for anyValQueryStringBindable.

}
"JavaScript Unbind Pferd as String which is a Boolean and uses special js unbind" in {
implicitly[PathBindable[Pferd]].javascriptUnbind must equalTo("function(k,v){return !!v}")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would fail without both fixes applied.

@mkurz mkurz merged commit 0cf2060 into playframework:main Mar 15, 2023
24 checks passed
@mkurz mkurz deleted the pathbindable_bugfixes branch March 15, 2023 23:06
mergify bot added a commit that referenced this pull request Mar 16, 2023
[2.8.x] Fix transforming of PathBindable and also the anyValPathBindable macro (backport #11712) by @mkurz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant