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

utf8 decode #22

Open
AlexProfi opened this issue Mar 14, 2019 · 4 comments
Open

utf8 decode #22

AlexProfi opened this issue Mar 14, 2019 · 4 comments

Comments

@AlexProfi
Copy link

hello how to use it like I do it in python
s=b"\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0\xB2\xD0\xB0"

print(s.decode("utf-8"))
Москва
lua 5.2 works similary
lua5.2
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
s="\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0\xB2\xD0\xB0"
print(s)
Москва

but lua 5.1
lua5.1
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

s="\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0\xB2\xD0\xB0"
print(s)
xD0x9CxD0xBExD1x81xD0xBAxD0xB2xD0xB0

how to make similar as in python or lua 5.2 with this lib?
what function I need to use?

@starwing
Copy link
Owner

You could try utf8.escape()

@AlexProfi
Copy link
Author

I use make with this Makefile

lua-utf8.so:lutf8lib.c
	gcc -shared -o lua-utf8.so  -I/usr/local/include/luajit-2.1  ./lutf8lib.c -fPIC

then i add this module to cpath in nginx config

I use lua-nginx-module
Then in my code I wrote
local utf8 = require 'lua-utf8'
local i_dn = ngx.var.ssl_client_i_dn_legacy
local sprintf = string.format
local response = sprintf(" ISSUER: %s ,
    utf8.escape(i_dn))
ngx.say(response)

i_dn="\U0433.\U041C\U043E\U0441\U043A\U0432\U0430"
in above example

And in the logs nginx I get error
attempt to index local 'utf8' (a function value)
How to fix this

@ghost
Copy link

ghost commented Mar 15, 2019

try local utf8 = require("lua-utf8") instead

@AlexProfi
Copy link
Author

Thanks errors desappered but I also get this result in output
\xD0\xB3.\xD0\x9C\xD0\xBE\xD1\x81\xD0\xBA\xD0\xB2\xD0\xB0/
I change src of nginx and it resolve issue

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

No branches or pull requests

2 participants