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

Tag value parsing includes extra characters (": ") #1702

Closed
501st-alpha1 opened this issue Jan 11, 2019 · 5 comments
Closed

Tag value parsing includes extra characters (": ") #1702

501st-alpha1 opened this issue Jan 11, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@501st-alpha1
Copy link

Anywhere that I try to match the value of a tag, if I try matching e.g. Value, it doesn't work, but if I instead match : Value (that's a colon and a space prepended to the value), it does. An MCVE:

For ledgerfile:

tag Foo
    assert value =~ /^: Bar$/

2019/01/01 * Payee
    ;; Foo: Bar
    Income:Foo    $-1
    Assets:Cash    $1
2019/01/01 * Another Payee
    Assets:Cash   $-1
    Expenses:Baz   $1

running ledger bal works. If line 2 is changed to assert value =~ /^Bar$/, it gives the error:

While parsing file "test.ledger", line 7:
Error: Metadata assertion failed for (Foo: : Bar): (value =~ /^Bar$/)

The behavior is the same for --limit args, as well as when using direct comparison instead of a regex. I.e.:

ledger bal --limit 'tag("Foo") == ": Bar"'

shows the correct results, while:

ledger bal --limit 'tag("Foo") == "Bar"'

returns nothing.

I tested this on 863cb3b, which is the latest next at present.

@tbm
Copy link
Contributor

tbm commented Jan 11, 2019

I don't know why ledger behaves the way you describe, but your example contains a syntax error:

;; Foo: Bar

There should be only one semi colon. If you fix that, it will work as expected.

@501st-alpha1
Copy link
Author

@tbm Interesting, that does indeed fix it for me.

My understanding was that since ; begins a comment, it shouldn't matter if I add another semicolon, so I have done that because I like how it looks better. It does make sense that using comments for metadata could affect this, but I haven't had any other issues with doing this. To give a specific example, I place effective dates (e.g. [=2019/01/01]) behind such comments, and they are parsed fine.

Would it cause any problems to allow double semicolons before metadata tags?

@tbm
Copy link
Contributor

tbm commented Feb 16, 2019

Interesting, yeah, I tend to agree that this is a bug that should be fixed.

@tbm tbm added the bug Something isn't working label Feb 16, 2019
@mbudde
Copy link
Contributor

mbudde commented Feb 16, 2019

The current behavior isn't very consistent at all:

; Tag: Value                 - Allowed
;; Tag: Value                - Allowed
;;; Tag: Value               - Not allowed
; ; ; Tag: Value             - Allowed
;; ;; Tag: Value             - Not allowed
; a b c Tag: Value           - Allowed
; abc Tag: Value             - Not allowed

mbudde added a commit to mbudde/ledger that referenced this issue Feb 16, 2019
If a tag is more than 2 characters from the beginning of the comment the
tag value offset will be wrong. ledger#1702 gives an example where the tag
line starts with `;;` and the tag value thus becomes `: Bar` because of
this bug.

The use `index` in the offset calulation seems to be a lucky coincidence
that works in the common case: "; tag: value"

Fixes ledger#1702
@enderw88
Copy link
Member

enderw88 commented Feb 16, 2019 via email

mbudde added a commit to mbudde/ledger that referenced this issue Mar 29, 2019
If a tag is more than 2 characters from the beginning of the comment the
tag value offset will be wrong. ledger#1702 gives an example where the tag
line starts with `;;` and the tag value thus becomes `: Bar` because of
this bug.

The use `index` in the offset calulation seems to be a lucky coincidence
that works in the common case: "; tag: value"

Fixes ledger#1702
tbm pushed a commit that referenced this issue Mar 30, 2019
If a tag is more than 2 characters from the beginning of the comment the
tag value offset will be wrong. #1702 gives an example where the tag
line starts with `;;` and the tag value thus becomes `: Bar` because of
this bug.

The use `index` in the offset calulation seems to be a lucky coincidence
that works in the common case: "; tag: value"

Fixes #1702
@tbm tbm closed this as completed in fbf8b24 Mar 30, 2019
bkuhn pushed a commit to bkuhn/ledger that referenced this issue Apr 30, 2020
If a tag is more than 2 characters from the beginning of the comment the
tag value offset will be wrong. ledger#1702 gives an example where the tag
line starts with `;;` and the tag value thus becomes `: Bar` because of
this bug.

The use `index` in the offset calulation seems to be a lucky coincidence
that works in the common case: "; tag: value"

Fixes ledger#1702
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants