-
Notifications
You must be signed in to change notification settings - Fork 2
/
0009-Fix-bad-escape-in-JSON-return-for-list-share.patch
112 lines (102 loc) · 3.77 KB
/
0009-Fix-bad-escape-in-JSON-return-for-list-share.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From ded1ca62ca6a1ab9fa51dec21c3160eb8a2bfc70 Mon Sep 17 00:00:00 2001
From: mozbugbox <[email protected]>
Date: Thu, 17 Mar 2016 21:42:29 +0800
Subject: [PATCH 09/10] Fix bad escape in JSON return for list share
baidu escapes ' with \ which is invalid for JSON. Python
json parser cannot handle invalid escape very well.
---
bcloud/pcs.py | 16 +++++++++-------
bcloud/util.py | 6 ++++++
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/bcloud/pcs.py b/bcloud/pcs.py
index 89e2fae..bff4f1e 100644
--- a/bcloud/pcs.py
+++ b/bcloud/pcs.py
@@ -10,6 +10,7 @@
import json
import os
import re
+import traceback
from lxml import html
from lxml.cssselect import CSSSelector as CSS
@@ -168,6 +169,7 @@ def list_share_single_file(cookie, tokens, uk, shareid):
else:
json_str = script.text[start+33:end]
try:
+ json_str = util.fix_json_escape(json_str)
return json.loads(json.loads(json_str))
except ValueError:
logger.warn(traceback.format_exc())
@@ -270,7 +272,7 @@ def verify_share_password(cookie, uk, shareid, pwd, vcode=''):
'''验证共享文件的密码.
如果密码正确, 会在返回的请求头里加入一个cookie: BDCLND
-
+
pwd - 四位的明文密码
vcode - 验证码; 目前还不支持
'''
@@ -559,7 +561,7 @@ def mkdir(cookie, tokens, path):
@return 返回一个dict, 里面包含了fs_id, ctime等信息.
'''
url = ''.join([
- const.PAN_API_URL,
+ const.PAN_API_URL,
'create?a=commit&channel=chunlei&clienttype=0&web=1',
'&bdstoken=', tokens['bdstoken'],
])
@@ -843,7 +845,7 @@ def rapid_upload(cookie, tokens, source_path, path, upload_mode):
def slice_upload(cookie, data):
'''分片上传一个大文件
-
+
分片上传完成后, 会返回这个分片的MD5, 用于最终的文件合并.
如果上传失败, 需要重新上传.
不需要指定上传路径, 上传后的数据会被存储在服务器的临时目录里.
@@ -943,7 +945,7 @@ def search(cookie, tokens, key, path='/'):
def cloud_add_link_task(cookie, tokens, source_url, save_path,
vcode='', vcode_input=''):
'''新建离线下载任务.
-
+
source_url - 可以是http/https/ftp等一般的链接
可以是eMule这样的链接
path - 要保存到哪个目录, 比如 /Music/, 以/开头, 以/结尾的绝对路径.
@@ -1049,7 +1051,7 @@ def cloud_query_sinfo(cookie, tokens, source_path):
def cloud_query_magnetinfo(cookie, tokens, source_url, save_path):
'''获取磁链的信息.
-
+
在新建磁链任务时, 要先获取这个磁链的信息, 比如里面包含哪些文件, 文件的名
称与大小等.
@@ -1077,7 +1079,7 @@ def cloud_query_magnetinfo(cookie, tokens, source_url, save_path):
def cloud_list_task(cookie, tokens, start=0):
'''获取当前离线下载的任务信息
-
+
start - 从哪个任务开始, 从0开始计数, 会获取这50条任务信息
'''
url = ''.join([
@@ -1121,7 +1123,7 @@ def cloud_query_task(cookie, tokens, task_ids):
def cloud_cancel_task(cookie, tokens, task_id):
'''取消离线下载任务.
-
+
task_id - 之前建立离线下载任务时的task id, 也可以从cloud_list_task()里
获取.
'''
diff --git a/bcloud/util.py b/bcloud/util.py
index b289759..3a66bd6 100644
--- a/bcloud/util.py
+++ b/bcloud/util.py
@@ -208,3 +208,9 @@ def validate_pathname(filepath):
if path[0] in filter3 or path[-1] in filter3:
return ValidatePathState.CHAR_ERROR3
return ValidatePathState.OK
+
+def fix_json_escape(json_str):
+ # Remove invalid escape
+ json_str = re.sub(r'\\(?![\\"/bfnrt])', "", json_str)
+ return json_str
+
--
2.9.0