GithubHelp home page GithubHelp logo

viur-framework / logics Goto Github PK

View Code? Open in Web Editor NEW
8.0 8.0 4.0 455 KB

A multi-platform, sandboxed and extendable expression language with a Python-like syntax.

License: MIT License

Python 48.97% Makefile 0.26% HTML 1.05% JavaScript 49.72%
arithmetic domain-specific-language formula-parser python template-engine template-language vistache viur viur-logics

logics's People

Contributors

leopoldwichtel avatar phorward avatar sveneberth avatar xnopasaranx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logics's Issues

Division by zero should return str "#ERR: division by zero"

In Logics, division by zero should be handled and return a str "#ERR: division by zero"

Python 3.11.5 (main, Aug 28 2023, 20:02:58) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logics
>>> logics.Value("10") // 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/logics/logics-py/logics/value.py", line 264, in __floordiv__
    return Value(int(self) // int(other))
                 ~~~~~~~~~~^^~~~~~~~~~~~
ZeroDivisionError: integer division or modulo by zero
>>> logics.Value("10") / 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/logics/logics-py/logics/value.py", line 260, in __truediv__
    return Value(int(self) / int(other))
                 ~~~~~~~~~~^~~~~~~~~~~~
ZeroDivisionError: division by zero

Add tuple syntax

A syntax for tuples should be made available, equal to lists.

  • [1, 2, 3] equals to (1, 2, 3)
  • [1] equals to (1, )

This is only for syntactical co-existence with Python's syntax.
Lists are not considered to be mutable in Logics, equal to tuples in Python.

Establishing a test suite

It would be great to have logics-py and logics-js being tested against a test-suite with, to ensure equal results in both implementations.

Implement slice notations

Slice-notations like x[from:until] should also be supported by logics to implement several custom issues.

logics-js: `max` function not working

This test case:

max(3, 7, 2) == 7
#EXPECT:True

does not work in logics-js but it works in logics-py
The problem seems to be with the max function, because the min function works.

Here is a screenshot with the case in logics-js:
grafik

EDIT: The min function is not working correct too.
grafik
It seems that only the first value is taken into account

EDIT2: For the max function its the same like the min function, only the first value is taken into account

security: Introduce a stack limit

To further improve the security features of Logics, it is necessary to set a stack limit. if the execution stack exceeds a certain limit, the program execution should be interrupted with an error string.

logics-py: `sum` function not working

This test case:

8724 < sum([x * x for x in (500, 1000, 90, 250, 25) if x < 100])
#EXPECT:True

does not work in logics-py but it works in logics-js

The problem seems to be with the sum function as the comprehension produces the right result
Here is a screenshot with both cases.

grafik

Add on `list` should be possible

Adding e.g. an int to a list is currently failing. It should be handled like in LeopoldWichtel@4308c2d

>>> logics.Value([1,2,3]) + 4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/logics/logics-py/logics/value.py", line 221, in __add__
    return Value(int(self) + int(other))
                 ^^^^^^^^^
  File "/tmp/logics/logics-py/logics/value.py", line 138, in __int__
    return int(self.value)
           ^^^^^^^^^^^^^^^
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
>>>

Generelly, an Exception shall not be thrown in this case.

I have a question?

my input like flow
{"tags" : ["dog","black"," female"],“name”:"dog1"}
{"tags" : ["pig","black"," female"],“name”:"pig1"}
{"tags" : ["cow","black"," female"],“name”:"cow1"}

my rule like this :
tags = dog

My expected output is
true
false
fase

Can we do that?

`logics` CLI not working when installed from PyPI

I installed logics

$ python -m pip install logics-py -U
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: logics-py in /home/sven/.local/lib/python3.10/site-packages (0.0.3)

and tried to run the CLI

$ python -m logics
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/sven/.local/lib/python3.10/site-packages/logics/__main__.py", line 2, in <module>
    from logics import Logics
ImportError: cannot import name 'Logics' from 'logics' (unknown location)

But this failed. How can I test expression?

Allow for a keyword-argument syntax in function calls

Functions currently can only be called with positional arguments.
This is not useful, especially because there are function with default values.
Syntax for keyword-arguments with a specific abstraction in both implementations has to be established.

Respect string length limitations in standard userspace functions

Currently, MAX_STRING_LENGTH (logics-py) / maxStringLength (logics-js) are not enforced in all situations and can be bypassed. This vulnerability should be closed in favor of security.

This issue serves as a documentation of several vulnerable problems relating the limitation settings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.