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

[BUG] The [not set] value is being output as a string in v1.3.0 #233

Open
bungoume opened this issue Dec 25, 2023 · 3 comments
Open

[BUG] The [not set] value is being output as a string in v1.3.0 #233

bungoume opened this issue Dec 25, 2023 · 3 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@bungoume
Copy link
Contributor

Describe the problem
When concatenating the not_set value with a string, it outputs the value '[not set]'.
This value shouldn't be outputted originally.

Expected behavior

// @scope: recv
// @suite: print not_set as empty
sub test_recv {
    declare local var.NOTSET STRING;
    declare local var.message STRING;

    set var.message = var.NOTSET;
    assert.equal(var.message, "");

    set var.message = "output:" var.NOTSET;
    assert.equal(var.message, "output:");
}

This should pass, but in falco v1.3.0, it results in the following error.

    Assertion Error: Assertion error: expect=output:, actual=output:[not set]
    Actual Value: output:[not set]

    10|     set var.message = "output:" var.NOTSET;
    11|     assert.equal(var.message, "output:");
    12| }

Additional context
I have prepared various test cases related to 'empty'.
https://github.com/bungoume/falco-vcl-empty-test/blob/main/tests/empty.test.vcl

@ysugimoto
Copy link
Owner

Blocking this problem by VCL behavior https://fiddle.fastly.dev/fiddle/e9852716

@ysugimoto ysugimoto added the help wanted Extra attention is needed label Dec 25, 2023
@bungoume
Copy link
Contributor Author

https://developer.fastly.com/reference/vcl/types/string/

Various functions and operators treat unset strings differently; some render them as the empty string, and some as "(null)". This handling is a property of the function (or operator), rather than a property of the STRING type.
A not set value is converted to an empty string when assigned to a STRING variable

This is quite difficult...

Here is the test and understanding based on my own fiddle test results.
https://fiddle.fastly.dev/fiddle/116ac5ce

sub test_recv {
    declare local var.NOTSET STRING;
    declare local var.message STRING;

    set req.http.MESSAGE = var.NOTSET;  # Looks like same process as `unset req.http.MESSAGE;`
    assert.is_notset(req.http.MESSAGE);

    set var.message = var.NOTSET;  # auto convert empty string
    assert.equal(var.message, "");

    set req.http.MESSAGE = "var:" var.NOTSET;  # render as `(null)`
    assert.equal(req.http.MESSAGE, "var:(null)");

    set var.message = "var:" var.NOTSET;  # render as ``(empty string)
    assert.equal(var.message, "var:");
}

@ysugimoto
Copy link
Owner

Understood, we will try to follow VCL's behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants