Coder Social home page Coder Social logo

philjackson.github.io's People

Contributors

philjackson avatar

Watchers

 avatar  avatar

philjackson.github.io's Issues

Handle double quotes in environment variable's value and prevent elisp code execution

Hi,

I like your function in https://github.com/philjackson/philjackson.github.io/blob/master/_posts/2021-07-26-export-an-environment-variable-to-emacs.md, but had a small issue with this:

$ export ASHTAS='abc " def""'
$ emacs-export ASHTAS
*ERROR*: End of file during parsing

and in emacs M-: (getenv "ASHTAS") returns nil.

It can also trigger execution of elisp code embedded in the environment variable and substitution of environment variables, at least, I was able to do this:

$ export ASHTAS='abc$PWD" (message "hello"));"'
$ emacs-export ASHTAS
$

then emacs displays "hello" in the echo area and in emacs M-: (getenv "ASHTAS") returns "abc/home/philjackson" (assuming your M-: default-directory is "/home/philjackson")

I fixed the function as follows to translate " to the octal escape sequence before sending the string

function export-emacs {
    if [ "$(emacsclient -e t)" != 't' ]; then
        return 1
    fi

    for name in "${@}"; do
        value=$(eval echo \"\${${name}//\\\"/\\\\042}\")
        emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
    done
}

Now M-: (let ((x (getenv "ASHTAS"))) (list x (length x))) returns ("abc \" def\"\"" 11) as expected.

Thank you for sharing your snippet! I would not have thought of writing it myself, but when I adopted it, I wanted to make it more robust. HTH!

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.