Skip to content

Match string in string#16

Closed
relvacode wants to merge 2 commits into
expr-lang:masterfrom
relvacode:master
Closed

Match string in string#16
relvacode wants to merge 2 commits into
expr-lang:masterfrom
relvacode:master

Conversation

@relvacode

Copy link
Copy Markdown

Adds ability to match if "foo" in "foobar"

@antonmedv

Copy link
Copy Markdown
Member

But we have matches. It does same think:

"foo" matches "foobar"

Is it?

@relvacode

Copy link
Copy Markdown
Author

These examples don't work in the same way as they would with in as they do with a regular expression match. To me they seem different enough.

"foobar" matches "foo"  (should be false)
"foo" matches "foobar"  (should be true)
"foobar" matches ""     (should be false)
"$1" matches "$1.50"    (should be true)
"foo" matches "foo.bar" (should be true)

@antonmedv

Copy link
Copy Markdown
Member

I see, not in operator supports both maps and arrays. Do you think it will be okay to override strings too?

@relvacode

Copy link
Copy Markdown
Author

I don't see why not. It works for me, would you like me to add tests for that?

@antonmedv

Copy link
Copy Markdown
Member

Ok, just please add type checks for strict mode. (See type.go)

@relvacode

Copy link
Copy Markdown
Author

Type checks added

@antonmedv

Copy link
Copy Markdown
Member

After discussion with my team we decided not to add this functionality as it can be error prone.
For example "" in bar if user expects bar to be an array he may check for empty string properly, but if bar ended up being string this check will always be try.
(In fact we see this errors in python)

As alternative is to define helper method:

Contains("foobar", "bar")

What do you think?

@antonmedv

Copy link
Copy Markdown
Member

I'm working on next expr version and it will have contains operator.

@antonmedv

Copy link
Copy Markdown
Member

Will be solved in #21

@antonmedv antonmedv closed this May 23, 2019
blitzy Bot pushed a commit to blitzy-research/expr that referenced this pull request Jul 16, 2026
Resolves all 19 QA review findings for the try/catch/finally/retry,
throw, errtype, and lazy try(expr, fallback) error-handling feature.

CRITICAL:
- #1 VM: add Program.verify() operand-domain + typed-constant + jump-target
  validation on the handler path; malformed programs become non-catchable
  fatal errors instead of catchable panics.
- #2 VM: validate handler-frame targets (OpTry catch strictly-forward,
  in-range, lands on OpCatch/OpPopHandler; OpSetupFinally lands on
  OpFinallyStart) in verify(); add 6 runtime phase guards + balanced-handler
  completion check.
- expr-lang#3 VM/builtin: control/safety errors (context.Canceled/DeadlineExceeded,
  ErrorMaxDepth, ErrMemoryBudget) are non-catchable via isNonRecoverable
  gate; add ErrMemoryBudget sentinel used by repeat().

MAJOR:
- expr-lang#4 VM: recovered panic(nil) is reported (panicNilError sentinel +
  finishedNormally/completed flags at both recover boundaries), not swallowed.
- expr-lang#5 builtin: panic-safe recovery-path message extraction (safeMessage +
  typed-nil guard) so a hostile Error()/typed-nil never escapes handleRecover.
- expr-lang#6 builtin/VM: retain original cause (unexported field + Cause() accessor);
  top-level recover wraps the cause so host errors.Is/As work; privacy
  invariant preserved (no Unwrap).
- expr-lang#7 VM: clear reclaimed scope/scopePool/Scopes slots to prevent cross-run
  value retention.
- expr-lang#8 builtin: classifyError bounded-BFS over Unwrap() error and []error;
  validCategory guard; non-error input -> custom.
- expr-lang#9 builtin: Type() returns "error" for RuntimeError (no internal-type leak
  on the Eval path).
- expr-lang#16 compiler tests: exact Bytecode/Arguments/disassembly + handler
  target/balance invariants for try/catch/finally/retry and lazy try().
- expr-lang#17 tests: fill public-API required-path gaps (fallback-error propagation,
  finally-after-catch-body-failure, retry-exhaustion-through-finally,
  errors.Is/As) plus adversarial/structural coverage.
- expr-lang#18 VM: restore no-handler fast path (hasHandler metadata + execute()
  extraction) and re-inline hot helpers via pre-built *fatalError sentinels;
  reuseVm back to pre-feature parity (~73 ns/op).
- expr-lang#19 builtin/expr: preserve backward-compat env overrides of try/throw/errtype
  in Eval via ErrorHandlingBuiltins + narrow parseForEval override detection.

MINOR:
- expr-lang#10/expr-lang#11 optimizer: single-pass O(N) protected-region marker; pass protected
  set to constExpr so lazy/catchable subtrees are never constant-folded.
- expr-lang#12 parser: reject bare try (no catch and no finally) with a source-anchored
  error at the try token.
- expr-lang#13 parser: reject reserved catch binding name "retry" with a precise
  diagnostic.
- expr-lang#14 ast: parenthesize TryCatchNode/ConditionalNode when rendered as a call
  callee / unary operand so printed source re-parses.
- expr-lang#15 docs: correct error-handling documentation (bare-try invalid, contextual
  retry, fatal-finally override, errtype classifier contract).

Validation: go build . / go vet ./... clean; go test ./... 56 ok / 0 FAIL;
race-clean; -tags=expr_debug TestDebugger pass; gofmt clean on all touched
files. No new third-party dependencies. Full backward compatibility preserved.
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.

2 participants