修复路径引号处理bug
This commit is contained in:
@@ -18,7 +18,9 @@
|
||||
- 输出:同上(可互相转换)
|
||||
|
||||
## 技术约定
|
||||
- 水印位置:右下角(距边 20px)
|
||||
- 水印样式:半透明黑色圆角背景 + 白色文字
|
||||
- 输出目录:output/
|
||||
- 水印位置:全屏平铺(小字16px,半透明60/255,类似身份证水印)
|
||||
- 输出目录:默认与输入同目录,加 _watermarked 后缀
|
||||
- 输出格式:支持指定路径或仅格式名(如 .jpg、result.jpg)
|
||||
- 统计文件:.processed_count(已加入 gitignore)
|
||||
- 路径处理:支持正斜杠/反斜杠,自动规范化
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ def process_single(image_arg, text):
|
||||
output_spec = None
|
||||
if ">" in image_arg:
|
||||
parts = image_arg.rsplit(">", 1)
|
||||
image_arg = parts[0].strip().strip('"').strip("'")
|
||||
image_arg = parts[0].strip().strip('"').strip("'") # 分割后去除左端引号
|
||||
output_spec = parts[1].strip()
|
||||
else:
|
||||
image_arg = image_arg.strip().strip('"').strip("'")
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def strip_quotes(s):
|
||||
"""去掉首尾的引号"""
|
||||
s = s.strip()
|
||||
if len(s) >= 2 and s[0] == s[-1] and s[0] in ('"', "'"):
|
||||
return s[1:-1]
|
||||
return s
|
||||
|
||||
# 测试用例
|
||||
test_cases = [
|
||||
('"D:\\桌面\\server-icon.png">d:/桌面/源码/1.bmp', 'test'),
|
||||
('D:\\桌面\\server-icon.png>.jpg', 'test'),
|
||||
('"D:\\桌面\\server-icon.png">.jpg', 'test'),
|
||||
]
|
||||
|
||||
for image_arg, text in test_cases:
|
||||
print(f'原始输入: {image_arg!r}')
|
||||
|
||||
# 第一步:去引号
|
||||
image_arg = strip_quotes(image_arg)
|
||||
text = strip_quotes(text)
|
||||
print(f' 去引号后: {image_arg!r}')
|
||||
|
||||
# 第二步:分割 >
|
||||
output_spec = None
|
||||
if '>' in image_arg:
|
||||
parts = image_arg.rsplit('>', 1)
|
||||
image_arg = parts[0].strip()
|
||||
output_spec = parts[1].strip()
|
||||
else:
|
||||
image_arg = image_arg.strip()
|
||||
|
||||
# 第三步:再次去引号(关键修复)
|
||||
image_arg = strip_quotes(image_arg)
|
||||
|
||||
print(f' 最终 input_path: {image_arg!r}')
|
||||
print(f' 文件存在: {os.path.isfile(image_arg)}')
|
||||
print(f' output_spec: {output_spec!r}')
|
||||
print()
|
||||
Reference in New Issue
Block a user