From 310376525b8644658983073517ae81b9b5f826bf Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 5 Nov 2024 21:40:44 +0100 Subject: [PATCH 1/2] [CHORE] Use forked `binding` library - Use the forked [binding](https://code.forgejo.org/go-chi/binding) library. This library has two benefits, it removes the usage of `github.com/goccy/go-json` (has no benefit as the minimo library is also using it). It adds the `TrimSpace` feature, which will during the binding part trim the spaces around the value it got from the form, this is done before validation. --- assets/go-licenses.json | 10 +++++----- go.mod | 2 +- go.sum | 4 ++-- modules/issue/template/template.go | 2 +- modules/validation/binding.go | 2 +- modules/validation/binding_test.go | 2 +- modules/validation/glob_pattern_test.go | 2 +- modules/validation/refname_test.go | 2 +- modules/validation/regex_pattern_test.go | 2 +- modules/validation/validurl_test.go | 2 +- modules/web/middleware/binding.go | 2 +- modules/web/route.go | 2 +- routers/api/v1/api.go | 2 +- routers/private/internal.go | 2 +- routers/web/auth/oauth.go | 2 +- routers/web/repo/issue.go | 2 +- routers/web/repo/setting/webhook.go | 2 +- services/forms/admin.go | 2 +- services/forms/auth_form.go | 2 +- services/forms/org.go | 2 +- services/forms/package_form.go | 2 +- services/forms/repo_branch_form.go | 2 +- services/forms/repo_form.go | 2 +- services/forms/repo_tag_form.go | 2 +- services/forms/runner.go | 2 +- services/forms/user_form.go | 2 +- services/forms/user_form_auth_openid.go | 2 +- services/webhook/discord.go | 2 +- services/webhook/slack.go | 2 +- services/webhook/sourcehut/builds.go | 2 +- 30 files changed, 35 insertions(+), 35 deletions(-) diff --git a/assets/go-licenses.json b/assets/go-licenses.json index 6bff22a505..bdb6071b7f 100644 --- a/assets/go-licenses.json +++ b/assets/go-licenses.json @@ -24,6 +24,11 @@ "path": "code.forgejo.org/forgejo/reply/LICENSE", "licenseText": "MIT License\n\nCopyright (c) The Forgejo Authors\nCopyright (c) Discourse\nCopyright (c) Claudemiro\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" }, + { + "name": "code.forgejo.org/go-chi/binding", + "path": "code.forgejo.org/go-chi/binding/LICENSE", + "licenseText": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n\"License\" shall mean the terms and conditions for use, reproduction, and\ndistribution as defined by Sections 1 through 9 of this document.\n\n\"Licensor\" shall mean the copyright owner or entity authorized by the copyright\nowner that is granting the License.\n\n\"Legal Entity\" shall mean the union of the acting entity and all other entities\nthat control, are controlled by, or are under common control with that entity.\nFor the purposes of this definition, \"control\" means (i) the power, direct or\nindirect, to cause the direction or management of such entity, whether by\ncontract or otherwise, or (ii) ownership of fifty percent (50%) or more of the\noutstanding shares, or (iii) beneficial ownership of such entity.\n\n\"You\" (or \"Your\") shall mean an individual or Legal Entity exercising\npermissions granted by this License.\n\n\"Source\" form shall mean the preferred form for making modifications, including\nbut not limited to software source code, documentation source, and configuration\nfiles.\n\n\"Object\" form shall mean any form resulting from mechanical transformation or\ntranslation of a Source form, including but not limited to compiled object code,\ngenerated documentation, and conversions to other media types.\n\n\"Work\" shall mean the work of authorship, whether in Source or Object form, made\navailable under the License, as indicated by a copyright notice that is included\nin or attached to the work (an example is provided in the Appendix below).\n\n\"Derivative Works\" shall mean any work, whether in Source or Object form, that\nis based on (or derived from) the Work and for which the editorial revisions,\nannotations, elaborations, or other modifications represent, as a whole, an\noriginal work of authorship. For the purposes of this License, Derivative Works\nshall not include works that remain separable from, or merely link (or bind by\nname) to the interfaces of, the Work and Derivative Works thereof.\n\n\"Contribution\" shall mean any work of authorship, including the original version\nof the Work and any modifications or additions to that Work or Derivative Works\nthereof, that is intentionally submitted to Licensor for inclusion in the Work\nby the copyright owner or by an individual or Legal Entity authorized to submit\non behalf of the copyright owner. For the purposes of this definition,\n\"submitted\" means any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems, and\nissue tracking systems that are managed by, or on behalf of, the Licensor for\nthe purpose of discussing and improving the Work, but excluding communication\nthat is conspicuously marked or otherwise designated in writing by the copyright\nowner as \"Not a Contribution.\"\n\n\"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf\nof whom a Contribution has been received by Licensor and subsequently\nincorporated within the Work.\n\n2. Grant of Copyright License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable copyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the Work and such\nDerivative Works in Source or Object form.\n\n3. Grant of Patent License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable (except as stated in this section) patent license to make, have\nmade, use, offer to sell, sell, import, and otherwise transfer the Work, where\nsuch license applies only to those patent claims licensable by such Contributor\nthat are necessarily infringed by their Contribution(s) alone or by combination\nof their Contribution(s) with the Work to which such Contribution(s) was\nsubmitted. If You institute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work or a\nContribution incorporated within the Work constitutes direct or contributory\npatent infringement, then any patent licenses granted to You under this License\nfor that Work shall terminate as of the date such litigation is filed.\n\n4. Redistribution.\n\nYou may reproduce and distribute copies of the Work or Derivative Works thereof\nin any medium, with or without modifications, and in Source or Object form,\nprovided that You meet the following conditions:\n\nYou must give any other recipients of the Work or Derivative Works a copy of\nthis License; and\nYou must cause any modified files to carry prominent notices stating that You\nchanged the files; and\nYou must retain, in the Source form of any Derivative Works that You distribute,\nall copyright, patent, trademark, and attribution notices from the Source form\nof the Work, excluding those notices that do not pertain to any part of the\nDerivative Works; and\nIf the Work includes a \"NOTICE\" text file as part of its distribution, then any\nDerivative Works that You distribute must include a readable copy of the\nattribution notices contained within such NOTICE file, excluding those notices\nthat do not pertain to any part of the Derivative Works, in at least one of the\nfollowing places: within a NOTICE text file distributed as part of the\nDerivative Works; within the Source form or documentation, if provided along\nwith the Derivative Works; or, within a display generated by the Derivative\nWorks, if and wherever such third-party notices normally appear. The contents of\nthe NOTICE file are for informational purposes only and do not modify the\nLicense. You may add Your own attribution notices within Derivative Works that\nYou distribute, alongside or as an addendum to the NOTICE text from the Work,\nprovided that such additional attribution notices cannot be construed as\nmodifying the License.\nYou may add Your own copyright statement to Your modifications and may provide\nadditional or different license terms and conditions for use, reproduction, or\ndistribution of Your modifications, or for any such Derivative Works as a whole,\nprovided Your use, reproduction, and distribution of the Work otherwise complies\nwith the conditions stated in this License.\n\n5. Submission of Contributions.\n\nUnless You explicitly state otherwise, any Contribution intentionally submitted\nfor inclusion in the Work by You to the Licensor shall be under the terms and\nconditions of this License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify the terms of\nany separate license agreement you may have executed with Licensor regarding\nsuch Contributions.\n\n6. Trademarks.\n\nThis License does not grant permission to use the trade names, trademarks,\nservice marks, or product names of the Licensor, except as required for\nreasonable and customary use in describing the origin of the Work and\nreproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty.\n\nUnless required by applicable law or agreed to in writing, Licensor provides the\nWork (and each Contributor provides its Contributions) on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,\nincluding, without limitation, any warranties or conditions of TITLE,\nNON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are\nsolely responsible for determining the appropriateness of using or\nredistributing the Work and assume any risks associated with Your exercise of\npermissions under this License.\n\n8. Limitation of Liability.\n\nIn no event and under no legal theory, whether in tort (including negligence),\ncontract, or otherwise, unless required by applicable law (such as deliberate\nand grossly negligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special, incidental,\nor consequential damages of any character arising as a result of this License or\nout of the use or inability to use the Work (including but not limited to\ndamages for loss of goodwill, work stoppage, computer failure or malfunction, or\nany and all other commercial damages or losses), even if such Contributor has\nbeen advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability.\n\nWhile redistributing the Work or Derivative Works thereof, You may choose to\noffer, and charge a fee for, acceptance of support, warranty, indemnity, or\nother liability obligations and/or rights consistent with this License. However,\nin accepting such obligations, You may act only on Your own behalf and on Your\nsole responsibility, not on behalf of any other Contributor, and only if You\nagree to indemnify, defend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason of your\naccepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work\n\nTo apply the Apache License to your work, attach the following boilerplate\nnotice, with the fields enclosed by brackets \"[]\" replaced with your own\nidentifying information. (Don't include the brackets!) The text should be\nenclosed in the appropriate comment syntax for the file format. We also\nrecommend that a file or class name and description of purpose be included on\nthe same \"printed page\" as the copyright notice for easier identification within\nthird-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License." + }, { "name": "code.forgejo.org/go-chi/cache", "path": "code.forgejo.org/go-chi/cache/LICENSE", @@ -74,11 +79,6 @@ "path": "git.sr.ht/~mariusor/go-xsd-duration/LICENSE", "licenseText": "MIT License\n\nCopyright (c) 2019 Go xsd:duration\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" }, - { - "name": "gitea.com/go-chi/binding", - "path": "gitea.com/go-chi/binding/LICENSE", - "licenseText": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n\"License\" shall mean the terms and conditions for use, reproduction, and\ndistribution as defined by Sections 1 through 9 of this document.\n\n\"Licensor\" shall mean the copyright owner or entity authorized by the copyright\nowner that is granting the License.\n\n\"Legal Entity\" shall mean the union of the acting entity and all other entities\nthat control, are controlled by, or are under common control with that entity.\nFor the purposes of this definition, \"control\" means (i) the power, direct or\nindirect, to cause the direction or management of such entity, whether by\ncontract or otherwise, or (ii) ownership of fifty percent (50%) or more of the\noutstanding shares, or (iii) beneficial ownership of such entity.\n\n\"You\" (or \"Your\") shall mean an individual or Legal Entity exercising\npermissions granted by this License.\n\n\"Source\" form shall mean the preferred form for making modifications, including\nbut not limited to software source code, documentation source, and configuration\nfiles.\n\n\"Object\" form shall mean any form resulting from mechanical transformation or\ntranslation of a Source form, including but not limited to compiled object code,\ngenerated documentation, and conversions to other media types.\n\n\"Work\" shall mean the work of authorship, whether in Source or Object form, made\navailable under the License, as indicated by a copyright notice that is included\nin or attached to the work (an example is provided in the Appendix below).\n\n\"Derivative Works\" shall mean any work, whether in Source or Object form, that\nis based on (or derived from) the Work and for which the editorial revisions,\nannotations, elaborations, or other modifications represent, as a whole, an\noriginal work of authorship. For the purposes of this License, Derivative Works\nshall not include works that remain separable from, or merely link (or bind by\nname) to the interfaces of, the Work and Derivative Works thereof.\n\n\"Contribution\" shall mean any work of authorship, including the original version\nof the Work and any modifications or additions to that Work or Derivative Works\nthereof, that is intentionally submitted to Licensor for inclusion in the Work\nby the copyright owner or by an individual or Legal Entity authorized to submit\non behalf of the copyright owner. For the purposes of this definition,\n\"submitted\" means any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems, and\nissue tracking systems that are managed by, or on behalf of, the Licensor for\nthe purpose of discussing and improving the Work, but excluding communication\nthat is conspicuously marked or otherwise designated in writing by the copyright\nowner as \"Not a Contribution.\"\n\n\"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf\nof whom a Contribution has been received by Licensor and subsequently\nincorporated within the Work.\n\n2. Grant of Copyright License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable copyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the Work and such\nDerivative Works in Source or Object form.\n\n3. Grant of Patent License.\n\nSubject to the terms and conditions of this License, each Contributor hereby\ngrants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,\nirrevocable (except as stated in this section) patent license to make, have\nmade, use, offer to sell, sell, import, and otherwise transfer the Work, where\nsuch license applies only to those patent claims licensable by such Contributor\nthat are necessarily infringed by their Contribution(s) alone or by combination\nof their Contribution(s) with the Work to which such Contribution(s) was\nsubmitted. If You institute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work or a\nContribution incorporated within the Work constitutes direct or contributory\npatent infringement, then any patent licenses granted to You under this License\nfor that Work shall terminate as of the date such litigation is filed.\n\n4. Redistribution.\n\nYou may reproduce and distribute copies of the Work or Derivative Works thereof\nin any medium, with or without modifications, and in Source or Object form,\nprovided that You meet the following conditions:\n\nYou must give any other recipients of the Work or Derivative Works a copy of\nthis License; and\nYou must cause any modified files to carry prominent notices stating that You\nchanged the files; and\nYou must retain, in the Source form of any Derivative Works that You distribute,\nall copyright, patent, trademark, and attribution notices from the Source form\nof the Work, excluding those notices that do not pertain to any part of the\nDerivative Works; and\nIf the Work includes a \"NOTICE\" text file as part of its distribution, then any\nDerivative Works that You distribute must include a readable copy of the\nattribution notices contained within such NOTICE file, excluding those notices\nthat do not pertain to any part of the Derivative Works, in at least one of the\nfollowing places: within a NOTICE text file distributed as part of the\nDerivative Works; within the Source form or documentation, if provided along\nwith the Derivative Works; or, within a display generated by the Derivative\nWorks, if and wherever such third-party notices normally appear. The contents of\nthe NOTICE file are for informational purposes only and do not modify the\nLicense. You may add Your own attribution notices within Derivative Works that\nYou distribute, alongside or as an addendum to the NOTICE text from the Work,\nprovided that such additional attribution notices cannot be construed as\nmodifying the License.\nYou may add Your own copyright statement to Your modifications and may provide\nadditional or different license terms and conditions for use, reproduction, or\ndistribution of Your modifications, or for any such Derivative Works as a whole,\nprovided Your use, reproduction, and distribution of the Work otherwise complies\nwith the conditions stated in this License.\n\n5. Submission of Contributions.\n\nUnless You explicitly state otherwise, any Contribution intentionally submitted\nfor inclusion in the Work by You to the Licensor shall be under the terms and\nconditions of this License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify the terms of\nany separate license agreement you may have executed with Licensor regarding\nsuch Contributions.\n\n6. Trademarks.\n\nThis License does not grant permission to use the trade names, trademarks,\nservice marks, or product names of the Licensor, except as required for\nreasonable and customary use in describing the origin of the Work and\nreproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty.\n\nUnless required by applicable law or agreed to in writing, Licensor provides the\nWork (and each Contributor provides its Contributions) on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,\nincluding, without limitation, any warranties or conditions of TITLE,\nNON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are\nsolely responsible for determining the appropriateness of using or\nredistributing the Work and assume any risks associated with Your exercise of\npermissions under this License.\n\n8. Limitation of Liability.\n\nIn no event and under no legal theory, whether in tort (including negligence),\ncontract, or otherwise, unless required by applicable law (such as deliberate\nand grossly negligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special, incidental,\nor consequential damages of any character arising as a result of this License or\nout of the use or inability to use the Work (including but not limited to\ndamages for loss of goodwill, work stoppage, computer failure or malfunction, or\nany and all other commercial damages or losses), even if such Contributor has\nbeen advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability.\n\nWhile redistributing the Work or Derivative Works thereof, You may choose to\noffer, and charge a fee for, acceptance of support, warranty, indemnity, or\nother liability obligations and/or rights consistent with this License. However,\nin accepting such obligations, You may act only on Your own behalf and on Your\nsole responsibility, not on behalf of any other Contributor, and only if You\nagree to indemnify, defend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason of your\naccepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work\n\nTo apply the Apache License to your work, attach the following boilerplate\nnotice, with the fields enclosed by brackets \"[]\" replaced with your own\nidentifying information. (Don't include the brackets!) The text should be\nenclosed in the appropriate comment syntax for the file format. We also\nrecommend that a file or class name and description of purpose be included on\nthe same \"printed page\" as the copyright notice for easier identification within\nthird-party archives.\n\n Copyright [yyyy] [name of copyright owner]\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License." - }, { "name": "gitea.com/lunny/levelqueue", "path": "gitea.com/lunny/levelqueue/LICENSE", diff --git a/go.mod b/go.mod index f99df48bc9..60b14837eb 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( code.forgejo.org/f3/gof3/v3 v3.7.0 code.forgejo.org/forgejo-contrib/go-libravatar v0.0.0-20191008002943-06d1c002b251 code.forgejo.org/forgejo/reply v1.0.2 + code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720 code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d code.forgejo.org/go-chi/captcha v0.0.0-20240905153133-df43b9250ed5 code.forgejo.org/go-chi/session v0.0.0-20241017103059-2a992261fc26 @@ -14,7 +15,6 @@ require ( code.gitea.io/sdk/gitea v0.17.1 codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570 connectrpc.com/connect v1.17.0 - gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 github.com/42wim/sshsig v0.0.0-20211121163825-841cf5bbc121 github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 diff --git a/go.sum b/go.sum index e799ddc69d..c2af9b3c36 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ code.forgejo.org/forgejo/archiver/v3 v3.5.1 h1:UmmbA7D5550uf71SQjarmrn6yKwOGxtEj code.forgejo.org/forgejo/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4= code.forgejo.org/forgejo/reply v1.0.2 h1:dMhQCHV6/O3L5CLWNTol+dNzDAuyCK88z4J/lCdgFuQ= code.forgejo.org/forgejo/reply v1.0.2/go.mod h1:RyZUfzQLc+fuLIGjTSQWDAJWPiL4WtKXB/FifT5fM7U= +code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720 h1:DDdvrdov1a6HK0xiJIUTfGh1RpKP0prkHi2guxhDKIU= +code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720/go.mod h1:fWwqaHj0H1/KeCpBqdvKunflq8pYfciEHI5v3UUeE2E= code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d h1:nOu/2GX571t4intmtfvpctS148OqsBYrGUySVm93ifc= code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d/go.mod h1:OVlZ/TqDYJ+RUJ+R+J+OLxtlyjo3pbjBeK7LAWAB+Vk= code.forgejo.org/go-chi/captcha v0.0.0-20240905153133-df43b9250ed5 h1:A7P1liXCpJBHEJ5KIDsF0ujnQ8FQ/aX1UixTW0vGrDQ= @@ -32,8 +34,6 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4HHsCo6xi2oWZYKWW4bly/Ory9FuTpFPRxj/mAg= git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs= -gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso= -gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw= gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 h1:IFT+hup2xejHqdhS7keYWioqfmxdnfblFDTGoOwcZ+o= gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go index 967bed0261..dbbc9e9186 100644 --- a/modules/issue/template/template.go +++ b/modules/issue/template/template.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/container" api "code.gitea.io/gitea/modules/structs" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // Validate checks whether an IssueTemplate is considered valid, and returns the first error diff --git a/modules/validation/binding.go b/modules/validation/binding.go index fe434500d5..1c81423ab3 100644 --- a/modules/validation/binding.go +++ b/modules/validation/binding.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/git" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" "github.com/gobwas/glob" ) diff --git a/modules/validation/binding_test.go b/modules/validation/binding_test.go index 01ff4e3435..4f1031abf3 100644 --- a/modules/validation/binding_test.go +++ b/modules/validation/binding_test.go @@ -8,7 +8,7 @@ import ( "net/http/httptest" "testing" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" chi "github.com/go-chi/chi/v5" "github.com/stretchr/testify/assert" ) diff --git a/modules/validation/glob_pattern_test.go b/modules/validation/glob_pattern_test.go index 1bf622e61d..42d86754e1 100644 --- a/modules/validation/glob_pattern_test.go +++ b/modules/validation/glob_pattern_test.go @@ -6,7 +6,7 @@ package validation import ( "testing" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" "github.com/gobwas/glob" ) diff --git a/modules/validation/refname_test.go b/modules/validation/refname_test.go index 3af7387c47..bb64cab51e 100644 --- a/modules/validation/refname_test.go +++ b/modules/validation/refname_test.go @@ -6,7 +6,7 @@ package validation import ( "testing" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) var gitRefNameValidationTestCases = []validationTestCase{ diff --git a/modules/validation/regex_pattern_test.go b/modules/validation/regex_pattern_test.go index efcb276734..90bd969c4f 100644 --- a/modules/validation/regex_pattern_test.go +++ b/modules/validation/regex_pattern_test.go @@ -7,7 +7,7 @@ import ( "regexp" "testing" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) func getRegexPatternErrorString(pattern string) string { diff --git a/modules/validation/validurl_test.go b/modules/validation/validurl_test.go index 39f7fa5d65..77fa7aa097 100644 --- a/modules/validation/validurl_test.go +++ b/modules/validation/validurl_test.go @@ -6,7 +6,7 @@ package validation import ( "testing" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) var urlValidationTestCases = []validationTestCase{ diff --git a/modules/web/middleware/binding.go b/modules/web/middleware/binding.go index bc0735b2cd..4e43f6d4b3 100644 --- a/modules/web/middleware/binding.go +++ b/modules/web/middleware/binding.go @@ -13,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/validation" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // Form form binding interface diff --git a/modules/web/route.go b/modules/web/route.go index 805fcb4411..eda6871d85 100644 --- a/modules/web/route.go +++ b/modules/web/route.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" "github.com/go-chi/chi/v5" ) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index b8f49a5bb6..718b27aeef 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -103,7 +103,7 @@ import ( _ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) func sudo() func(ctx *context.APIContext) { diff --git a/routers/private/internal.go b/routers/private/internal.go index 311f59b60e..dfbdc6967b 100644 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -15,7 +15,7 @@ import ( "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" chi_middleware "github.com/go-chi/chi/v5/middleware" ) diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index ee08b514b1..a9cbce9a9d 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -40,7 +40,7 @@ import ( remote_service "code.gitea.io/gitea/services/remote" user_service "code.gitea.io/gitea/services/user" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" "github.com/golang-jwt/jwt/v5" "github.com/markbates/goth" "github.com/markbates/goth/gothic" diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index a9351c6a55..6a485b0066 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -58,7 +58,7 @@ import ( pull_service "code.gitea.io/gitea/services/pull" repo_service "code.gitea.io/gitea/services/repository" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) const ( diff --git a/routers/web/repo/setting/webhook.go b/routers/web/repo/setting/webhook.go index eee493e2c2..af54997794 100644 --- a/routers/web/repo/setting/webhook.go +++ b/routers/web/repo/setting/webhook.go @@ -28,7 +28,7 @@ import ( "code.gitea.io/gitea/services/forms" webhook_service "code.gitea.io/gitea/services/webhook" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) const ( diff --git a/services/forms/admin.go b/services/forms/admin.go index d71fc076fc..1f055cff55 100644 --- a/services/forms/admin.go +++ b/services/forms/admin.go @@ -10,7 +10,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // AdminCreateUserForm form for admin to create user diff --git a/services/forms/auth_form.go b/services/forms/auth_form.go index a3eca9473b..f0da63155a 100644 --- a/services/forms/auth_form.go +++ b/services/forms/auth_form.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // AuthenticationForm form for authentication diff --git a/services/forms/org.go b/services/forms/org.go index db182f7e96..dea2e159e9 100644 --- a/services/forms/org.go +++ b/services/forms/org.go @@ -11,7 +11,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // ________ .__ __ .__ diff --git a/services/forms/package_form.go b/services/forms/package_form.go index 9b6f907164..d475d2f569 100644 --- a/services/forms/package_form.go +++ b/services/forms/package_form.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) type PackageCleanupRuleForm struct { diff --git a/services/forms/repo_branch_form.go b/services/forms/repo_branch_form.go index 42e6c85c37..186a4ad367 100644 --- a/services/forms/repo_branch_form.go +++ b/services/forms/repo_branch_form.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // NewBranchForm form for creating a new branch diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index c3d9c3edc9..63049284d0 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -21,7 +21,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // CreateRepoForm form for creating repository diff --git a/services/forms/repo_tag_form.go b/services/forms/repo_tag_form.go index 0135684737..38f5996db3 100644 --- a/services/forms/repo_tag_form.go +++ b/services/forms/repo_tag_form.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // ProtectTagForm form for changing protected tag settings diff --git a/services/forms/runner.go b/services/forms/runner.go index 6abfc66fc2..f933750858 100644 --- a/services/forms/runner.go +++ b/services/forms/runner.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // EditRunnerForm form for admin to create runner diff --git a/services/forms/user_form.go b/services/forms/user_form.go index 67c8f00715..afd3a42982 100644 --- a/services/forms/user_form.go +++ b/services/forms/user_form.go @@ -16,7 +16,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // InstallForm form for installation page diff --git a/services/forms/user_form_auth_openid.go b/services/forms/user_form_auth_openid.go index 595bfecad9..c5ab703fa1 100644 --- a/services/forms/user_form_auth_openid.go +++ b/services/forms/user_form_auth_openid.go @@ -9,7 +9,7 @@ import ( "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/services/context" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) // SignInOpenIDForm form for signing in with OpenID diff --git a/services/webhook/discord.go b/services/webhook/discord.go index b0142b8509..7741ceb10d 100644 --- a/services/webhook/discord.go +++ b/services/webhook/discord.go @@ -26,7 +26,7 @@ import ( "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/webhook/shared" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) type discordHandler struct{} diff --git a/services/webhook/slack.go b/services/webhook/slack.go index af93976bd6..1fa33444f3 100644 --- a/services/webhook/slack.go +++ b/services/webhook/slack.go @@ -22,7 +22,7 @@ import ( "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/webhook/shared" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" ) type slackHandler struct{} diff --git a/services/webhook/sourcehut/builds.go b/services/webhook/sourcehut/builds.go index 7b7ace15bb..5a34503a7d 100644 --- a/services/webhook/sourcehut/builds.go +++ b/services/webhook/sourcehut/builds.go @@ -24,7 +24,7 @@ import ( "code.gitea.io/gitea/services/forms" "code.gitea.io/gitea/services/webhook/shared" - "gitea.com/go-chi/binding" + "code.forgejo.org/go-chi/binding" "gopkg.in/yaml.v3" ) From 495274769973ad7a6531060c7bbfaf009cca671b Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 5 Nov 2024 22:05:35 +0100 Subject: [PATCH 2/2] [FEAT] Trim spaces from repository name - This uses the `TrimSpace` preprocessing of the binding library to remove any accidental spaces from the input. - Integration test added. - Resolves #4309 --- services/forms/repo_form.go | 2 +- tests/integration/repo_generate_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index 63049284d0..58c34473aa 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -27,7 +27,7 @@ import ( // CreateRepoForm form for creating repository type CreateRepoForm struct { UID int64 `binding:"Required"` - RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"` + RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)" preprocess:"TrimSpace"` Private bool Description string `binding:"MaxSize(2048)"` DefaultBranch string `binding:"GitRefName;MaxSize(100)"` diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go index c475c92eef..0b2870ad56 100644 --- a/tests/integration/repo_generate_test.go +++ b/tests/integration/repo_generate_test.go @@ -11,9 +11,11 @@ import ( "strings" "testing" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/tests" @@ -135,3 +137,19 @@ func TestRepoGenerateToOrg(t *testing.T) { testRepoGenerate(t, session, "44", "user27", "template1", user, org, "generated2") } + +func TestRepoCreateFormTrimSpace(t *testing.T) { + defer tests.PrepareTestEnv(t)() + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) + session := loginUser(t, user.Name) + + req := NewRequestWithValues(t, "POST", "/repo/create", map[string]string{ + "_csrf": GetCSRF(t, session, "/repo/create"), + "uid": "2", + "repo_name": " spaced-name ", + }) + resp := session.MakeRequest(t, req, http.StatusSeeOther) + + assert.EqualValues(t, "/user2/spaced-name", test.RedirectURL(resp)) + unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 2, Name: "spaced-name"}) +}