go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

funtion config.mustload in mode useEnv() can't parsed correctly for special characters like '$'

Open mvb-ai opened this issue 2 years ago • 2 comments
trafficstars

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

    Mongo:
    DataSource: mongodb://root:abcd!@#$5@${MONGO_MONGODB_SERVICE_HOST}:${MONGO_MONGODB_SERVICE_PORT}/?directConnection=true
    DataBase: ${MONGO_MONGODB_DATABASE}
    
    Cache:
    - Host: ${REDIS_MASTER_SERVICE_HOST}:${REDIS_MASTER_SERVICE_PORT}
       Pass: abcd!@#$%
       Type: node
    
  2. The error is

{
    "@timestamp":"2023-02-08T19:25:48.194+08:00",
    "caller":"internal/log.go:57",
    "content":"(/shopCustomer/shop/list?page=1&page_size=10&scene=user&tab=to_distribute&is_export=0) error parsing uri: unescaped @ sign in user info
goroutine 293 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:24 +0x65
github.com/zeromicro/go-zero/rest/handler.RecoverHandler.func1.1()
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/recoverhandler.go:16 +0x66
panic({0x1cf40c0, 0xc0001f3080})
/usr/local/go/src/runtime/panic.go:838 +0x207
bgbai/service/shop_customer/api/internal/svc.(*ServiceContext).InitCurrentUser(0xc0000cac00, {0xc000adc8d6, 0x20})
/build/service/shop_customer/api/internal/svc/ServiceContext.go:54 +0x3f7
bgbai/service/shop_customer/api/internal/handler/shop.ListShopHandleHandler.func1({0x22c9410, 0xc000a41f20}, 0xc000ac5c00)
/build/service/shop_customer/api/internal/handler/shop/ListShopHandleHandler.go:36 +0x1b2
net/http.HandlerFunc.ServeHTTP(0x1?, {0x22c9410?, 0xc000a41f20?}, 0xc000110550?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/internal/cors.Middleware.func1.1({0x22c9410, 0xc000a41f20}, 0xc000ac5c00)
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/internal/cors/handlers.go:59 +0xbe
net/http.HandlerFunc.ServeHTTP(0x0?, {0x22c9410?, 0xc000a41f20?}, 0x413f05?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/handler.GunzipHandler.func1({0x22c9410, 0xc000a41f20}, 0xc000ac5c00)
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/gunziphandler.go:26 +0xe9
net/http.HandlerFunc.ServeHTTP(0xedb757dbc?, {0x22c9410?, 0xc000a41f20?}, 0x58779e1848?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/handler.MaxBytesHandler.func2.1({0x22c9410?, 0xc000a41f20?}, 0x3304180?)
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/maxbyteshandler.go:24 +0xff
net/http.HandlerFunc.ServeHTTP(0x0?, {0x22c9410?, 0xc000a41f20?}, 0xc000110600?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/handler.MetricHandler.func1.1({0x22c9410, 0xc000a41f20}, 0x4?)
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/metrichandler.go:21 +0xd5
net/http.HandlerFunc.ServeHTTP(0xc000110730?, {0x22c9410?, 0xc000a41f20?}, 0xc000110748?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/handler.RecoverHandler.func1({0x22c9410?, 0xc000a41f20?}, 0x7c351f?)
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/recoverhandler.go:21 +0x83
net/http.HandlerFunc.ServeHTTP(0xc0000ec9b0?, {0x22c9410?, 0xc000a41f20?}, 0x4420e5?)
/usr/local/go/src/net/http/server.go:2084 +0x2f
github.com/zeromicro/go-zero/rest/handler.(*timeoutHandler).ServeHTTP.func1()
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/timeouthandler.go:79 +0x7c
created by github.com/zeromicro/go-zero/rest/handler.(*timeoutHandler).ServeHTTP
/go/pkg/mod/github.com/zeromicro/[email protected]/rest/handler/timeouthandler.go:73 +0x47b
",
    "level":"error",
    "span":"1664f0ca0ee1a732",
    "trace":"90a10b3cafbf2bcd82fe0c16eb2499ea"
}

Expected behavior A clear and concise description of what you expected to happen. I expected if my password include some special characters like '$' can be auto parsed correctly now i use env to replace these variables for the problem in mongodb i even need to use funtion urlencode to parsed uri

Screenshots If applicable, add screenshots to help explain your problem.

Environments (please complete the following information):

  • OS: [e.g. Linux]
  • go-zero version [e.g. 1.2.1]
  • goctl version [e.g. 1.2.1, optional]

More description Add any other context about the problem here.

mvb-ai avatar Feb 10 '23 04:02 mvb-ai

Add quotes in config:

Mongo:
  DataSource: "mongodb://root:abcd!@#$5@${MONGO_MONGODB_SERVICE_HOST}:${MONGO_MONGODB_SERVICE_PORT}/?directConnection=true"
  DataBase: ${MONGO_MONGODB_DATABASE}

Cache:
- Host: ${REDIS_MASTER_SERVICE_HOST}:${REDIS_MASTER_SERVICE_PORT}
   Pass: abcd!@#$%
   Type: node

kevwan avatar Feb 11 '23 06:02 kevwan

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Feb 12 '24 01:02 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar May 17 '24 01:05 github-actions[bot]