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

feat: override socket.url with patched.url for all imports #25

Merged
merged 1 commit into from
Sep 14, 2022

Conversation

omegabytes
Copy link
Contributor

@omegabytes omegabytes commented Aug 19, 2022

Updates socket.lua to return patched/url.lua so that imports of socket.url are overridden to implement patched.url instead.
Prior to this change, plugins using socket.url would need to be manually patched in order to function. By overriding the import, we ensure that custom plugins using socket.url work out-of-the-box.

Adds a test specifically for the socket.url <-> patched.url swap, and updates the diff in lua-tree.patch to reflect accurate diff.

Hold until after #27

@omegabytes omegabytes requested a review from a team as a code owner August 19, 2022 17:45
@CLAassistant
Copy link

CLAassistant commented Aug 19, 2022

CLA assistant check
All committers have signed the CLA.

@omegabytes
Copy link
Contributor Author

related to #26

Copy link
Contributor

@mikefero mikefero left a comment

Choose a reason for hiding this comment

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

Starting to come to shape; testing and regression issues currently.

},
},
},
},}
Copy link
Contributor

Choose a reason for hiding this comment

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

This schema needs more for the test; url is never used so there is no validation happening here. The current field uuid has no value for url. Create a custom_validator function to verify that url.parse(<a-url-field>) is working as expected:

<url> ::= <scheme>://<authority>/<path>;<params>?<query>#<fragment>
<authority> ::= <userinfo>@<host>:<port>
<userinfo> ::= <user>[:<password>]
<path> :: = {<segment>/}<segment>

You will want to check:

  • scheme
  • authority
  • userinfo
  • user
  • password
  • host
  • port
  • path
  • params
  • query
  • fragment

This test could also be extended to validated patched.url as well in the validator that way we are ensuring backwards compatibility through a regression.

pluginName, err := v.LoadSchema(string(schema))
assert.Equal(t, "patched-url-test", pluginName)
assert.Nil(t, err)
})
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in test schema; we need to increase the surface area of this test.

-
-return _M
+return require("patched.url")

Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't done so yet, but did you ensure the lua-tree.patch is still working correctly?

@omegabytes omegabytes force-pushed the feat/use-patched-url-by-default branch from d8b0c74 to ad9d9de Compare September 6, 2022 18:51
@omegabytes omegabytes force-pushed the feat/use-patched-url-by-default branch 3 times, most recently from 4c3740f to 6104892 Compare September 7, 2022 21:29
@omegabytes
Copy link
Contributor Author

@mikefero patch file is correct now, tests passing.

@omegabytes omegabytes force-pushed the feat/use-patched-url-by-default branch from 6104892 to 4edd380 Compare September 7, 2022 21:45
Comment on lines 14 to 17
lua-tree/share/lua/5.1/socket/url.lua
- override all imports of socket.url by returning patched.url


Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated at the bottom; we can remove this.

Suggested change
lua-tree/share/lua/5.1/socket/url.lua
- override all imports of socket.url by returning patched.url

@@ -72,6 +69,9 @@ tools/sandbox.lua
- set configuration.enabled to true
- set configuration.sandbox_enabled to true

lua-tree/share/lua/5.1/socket/url.lua
Copy link
Contributor

Choose a reason for hiding this comment

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

super duper nit: between each file we are using two newlines

Suggested change
lua-tree/share/lua/5.1/socket/url.lua
lua-tree/share/lua/5.1/socket/url.lua

@mikefero
Copy link
Contributor

@omegabytes Let's get #26 in first and then we can rebase this and fix it up; WDYT?

@mikefero
Copy link
Contributor

Found one more usage of patched.url in the patch file that needs to be removed:

diff --git a/patches/lua-tree.patch b/patches/lua-tree.patch
index 5953b79..eb93b27 100644
--- a/patches/lua-tree.patch
+++ b/patches/lua-tree.patch
@@ -683,15 +683,6 @@ index 08405b8..2b1157d 100644
  end

  -- function below is more acurate, but invalidates previously accepted uuids and hence causes
-@@ -273,7 +133,7 @@ end
- --end
-
- do
--  local url = require "socket.url"
-+  local url = require "patched.url"
-
-   --- URL escape and format key and value
-   -- values should be already decoded or the `raw` option should be passed to prevent double-encoding
 @@ -508,7 +368,18 @@ do
    local floor = math.floor
    local max = math.max

Updates socket.lua to return patched/url.lua so that imports
of socket.url are overridden to implement patched.url instead.
Prior to this change, plugins using socket.url would need to be
manually patched in order to function. By overriding the import,
we ensure that custom plugins using socket.url work out-of-the-box.
@omegabytes omegabytes force-pushed the feat/use-patched-url-by-default branch from f15d88e to d5dcad5 Compare September 14, 2022 16:30
Copy link
Contributor

@mikefero mikefero left a comment

Choose a reason for hiding this comment

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

Nice work!!!

@mikefero mikefero merged commit a40c4d2 into main Sep 14, 2022
@mikefero mikefero deleted the feat/use-patched-url-by-default branch September 14, 2022 18:01
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.

3 participants