From 63799b3c18b2511f51ccb1a985391ede641e8e93 Mon Sep 17 00:00:00 2001
From: Unknwon <u@gogs.io>
Date: Sat, 29 Aug 2015 12:08:37 +0800
Subject: [PATCH] #1526 URL escape for username and password

---
 models/models.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/models/models.go b/models/models.go
index 240c8ebca9..33db2ebac6 100644
--- a/models/models.go
+++ b/models/models.go
@@ -7,6 +7,7 @@ package models
 import (
 	"database/sql"
 	"fmt"
+	"net/url"
 	"os"
 	"path"
 	"strings"
@@ -133,7 +134,7 @@ func getEngine() (*xorm.Engine, error) {
 			port = fields[1]
 		}
 		cnnstr = fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=%s",
-			DbCfg.User, DbCfg.Passwd, host, port, DbCfg.Name, DbCfg.SSLMode)
+			url.QueryEscape(DbCfg.User), url.QueryEscape(DbCfg.Passwd), host, port, DbCfg.Name, DbCfg.SSLMode)
 	case "sqlite3":
 		if !EnableSQLite3 {
 			return nil, fmt.Errorf("Unknown database type: %s", DbCfg.Type)