Skip to content

fix: closing brace should not be a part of variable#10485

Merged
juststillthinking merged 6 commits into
apache:masterfrom
shreemaan-abhishek:fvr
Nov 24, 2023
Merged

fix: closing brace should not be a part of variable#10485
juststillthinking merged 6 commits into
apache:masterfrom
shreemaan-abhishek:fvr

Conversation

@shreemaan-abhishek

@shreemaan-abhishek shreemaan-abhishek commented Nov 13, 2023

Copy link
Copy Markdown
Contributor

Description

Current regex for evaluating variables like: $var, ${var}, etc. would also match $var} including the closing brace. This has been fixed.

Fixes #10478

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@shreemaan-abhishek
shreemaan-abhishek marked this pull request as draft November 14, 2023 01:02
@shreemaan-abhishek
shreemaan-abhishek marked this pull request as ready for review November 14, 2023 03:12
@juststillthinking

Copy link
Copy Markdown
Contributor

please make the ci pass

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor Author

done

Comment thread apisix/core/utils.lua Outdated
Comment on lines +299 to +304
local v = _ctx[m[1]]
local i = 1
-- if first capture's first char is "{" evaluate the second capture
if m[1]:byte(1) == 123 then
i = 2
end
local v = _ctx[m[i]]

@juststillthinking juststillthinking Nov 14, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you add this? we don't need this block to resolve this problem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this was to fix other test case failures. For example when var = ${alpha}, m[1] = {alpha} and m[2] = alpha. Only m[2] can be evaluated no m[1].

@juststillthinking juststillthinking added the wait for update wait for the author's response in this issue/PR label Nov 14, 2023
@shreemaan-abhishek shreemaan-abhishek removed the wait for update wait for the author's response in this issue/PR label Nov 15, 2023
Comment thread apisix/core/utils.lua Outdated
local v = _ctx[m[1]]
local i = 1
-- if first capture's first char is "{" evaluate the second capture
if m[1]:byte(1) == 123 then

@juststillthinking juststillthinking Nov 20, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can optimise this judgement, like

local variable = m[2] or m[3]
local v = _ctx[variable]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it works

@juststillthinking juststillthinking added the wait for update wait for the author's response in this issue/PR label Nov 21, 2023
@juststillthinking juststillthinking added approved and removed wait for update wait for the author's response in this issue/PR labels Nov 22, 2023
@juststillthinking
juststillthinking merged commit 1437b60 into apache:master Nov 24, 2023
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.

bug: incorrect variable extraction in the configuration

5 participants