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

Vala string templates formatting bug #4230

Open
rolandlo opened this issue Feb 6, 2024 · 2 comments
Open

Vala string templates formatting bug #4230

rolandlo opened this issue Feb 6, 2024 · 2 comments
Labels

Comments

@rolandlo
Copy link

rolandlo commented Feb 6, 2024

In the following Vala example the string argument of date.format inside a string template gets formatted (spaces are added), which shouldn't be the case and makes the URL invalid.

test file:

public void main () {
    var date = new DateTime.now_local ();

    string language = "en";
    string url =
        @"https://api.wikimedia.org/feed/v1/wikipedia/$language/featured/$(date.format ("%Y/%m/%d"))";

    print(url)
}

generated result:

public void main () {
    var date = new DateTime.now_local ();

    string language = "en";
    string url =
        @"https://api.wikimedia.org/feed/v1/wikipedia/$language/featured/$(date.format ("%Y/ %m/ %d "))";

    print(url)
}

expected result: same as test file

version: Uncrustify-0.78.1-104-b18da33ad

The issue was observed in workbenchdev/demos#69

@gmaurel gmaurel added the Vala label Feb 6, 2024
@guy-maurel
Copy link
Contributor

Why is the ", at line 7 column 89 NOT the closing of the string, beginning at column 10

@rolandlo
Copy link
Author

Why is the ", at line 7 column 89 NOT the closing of the string, beginning at column 10

Well, I don't know how the Vala compiler works, but in the string template $(....) is an expression and so the " at line 7 column 89, which appears in that expression (before the bracket after the $-sign is closed) cannot be the closing of the string.
From this Vala tutorial

Strings prefixed with '@' are string templates. They can evaluate embedded variables and expressions prefixed with '$':

int a = 6, b = 7;
string s = @"$a * $b = $(a * b)";  // => "6 * 7 = 42"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants