特殊字符(例如

发布于 2025-01-31 14:36:28 字数 2541 浏览 2 评论 0原文

我已经浏览了类似的帖子,但这并没有解决我的问题。

àvengers15)时,这反过

*******
    ([a-zA-Z0-9 +-.'/\\&-\\\u00a2\\\u00c0\\\u00c1\\\u00c2\\\u00c3\\\u00c4\\\u00c5\\\u00c6\\\u00c7\\\u00c8\\\u00c9\\\u00ca\\\u00cb\\\u00cc\\\u00cd\\\u00ce\\\u00cf\\\u00d0\\\u00d1\\\u00d2\\\u00d3\\\u00d4\\\u00d5\\\u00d6\\\u00d8\\\u00d9\\\u00da\\\u00db\\\u00dc\\\u00dd\\\u00de\\\u00df\\\u00e0\\\u00e1\\\u00e2\\\u00e3\\\u00e4\\\u00e5\\\u00e6\\\u00e7\\\u00e8\\\u00e9\\\u00ea\\\u00eb\\\u00ec\\\u00ed\\\u00ee\\\u00ef\\\u00f0\\\u00f1\\\u00f2\\\u00f3\\\u00f4\\\u00f5\\\u00f6\\\u00f8\\\u00f9\\\u00fa\\\u00fb\\\u00fc\\\u00fd\\\u00fe\\\u00ff\\\u0100\\\u0101\\\u0102\\\u0103\\\u0104\\\u0105\\\u0106\\\u0107\\\u0108\\\u0109\\\u010a\\\u010b\\\u010c\\\u010d\\\u010e\\\u010f\\\u0110\\\u0111\\\u0112\\\u0113\\\u0114\\\u0115\\\u0116\\\u0117\\\u0118\\\u0119\\\u011a\\\u011b\\\u011c\\\u011d\\\u011e\\\u011f\\\u0120\\\u0121\\\u0122\\\u0123\\\u0124\\\u0125\\\u0126\\\u0127\\\u0128\\\u0129\\\u012a\\\u012b\\\u012c\\\u012d\\\u012e\\\u012f\\\u0130\\\u0131\\\u0132\\\u0133\\\u0134\\\u0135\\\u0136\\\u0137\\\u0138\\\u0139\\\u013a\\\u013b\\\u013c\\\u013d\\\u013e\\\u013f\\\u0140\\\u0141\\\u0142\\\u0143\\\u0144\\\u0145\\\u0146\\\u0147\\\u0148\\\u014a\\\u014b\\\u014c\\\u014d\\\u014e\\\u014f\\\u0150\\\u0151\\\u0152\\\u0153\\\u0154\\\u0155\\\u0156\\\u0157\\\u0158\\\u0159\\\u015a\\\u015b\\\u015c\\\u015d\\\u015e\\\u015f\\\u0160\\\u0161\\\u0162\\\u0163\\\u0164\\\u0165\\\u0166\\\u0167\\\u0168\\\u0169\\\u016a\\\u016b\\\u016c\\\u016d\\\u016e\\\u016f\\\u0170\\\u0171\\\u0172\\\u0173\\\u0174\\\u0175\\\u0176\\\u0177\\\u0178\\\u0179\\\u017a\\\u017b\\\u017c\\\u017d\\\u017e\\\u0218\\\u0219\\\u021a\\\u021b]{1,60}) 
******

当我提供来自UI属性的特殊字符(例如名称= 在响应

*****
    pattern.matcher(val);
    boolean valid =  matcher.matches()
    valid = true
*****

*****
    <meta charset="UTF-8">
*****

但是,当我直接通过SOAPUI直接使用与上面的数据击中API时,为JSON有效载荷提供了与UI相同的数据,例如UI EG“ first_name”:“àvengers15”。我得到的响应

*****
    pattern.matcher(val);
    boolean valid =  matcher.matches()
    valid = false
*****

。不起作用。

*****
    byte[] ptext = attrValue.getBytes();
    String valueAfterUtf = new String(ptext, "UTF-8");
*****

另外,尝试设置 'content-type','应用程序/json; charset = utf-8'在标题中无效。

 1. Why am I getting question mark , if UTF-8 has been handled in case of UI.
 2. Why validation is failing through SOAPUI.

任何帮助将不胜感激。 谢谢

I have gone through similar posts , but it didn't resolve my issue.

When I am providing special char from UI attribute(e.g First Name = Àvengers15) , which in turn is validating against Regex pattern

*******
    ([a-zA-Z0-9 +-.'/\\&-\\\u00a2\\\u00c0\\\u00c1\\\u00c2\\\u00c3\\\u00c4\\\u00c5\\\u00c6\\\u00c7\\\u00c8\\\u00c9\\\u00ca\\\u00cb\\\u00cc\\\u00cd\\\u00ce\\\u00cf\\\u00d0\\\u00d1\\\u00d2\\\u00d3\\\u00d4\\\u00d5\\\u00d6\\\u00d8\\\u00d9\\\u00da\\\u00db\\\u00dc\\\u00dd\\\u00de\\\u00df\\\u00e0\\\u00e1\\\u00e2\\\u00e3\\\u00e4\\\u00e5\\\u00e6\\\u00e7\\\u00e8\\\u00e9\\\u00ea\\\u00eb\\\u00ec\\\u00ed\\\u00ee\\\u00ef\\\u00f0\\\u00f1\\\u00f2\\\u00f3\\\u00f4\\\u00f5\\\u00f6\\\u00f8\\\u00f9\\\u00fa\\\u00fb\\\u00fc\\\u00fd\\\u00fe\\\u00ff\\\u0100\\\u0101\\\u0102\\\u0103\\\u0104\\\u0105\\\u0106\\\u0107\\\u0108\\\u0109\\\u010a\\\u010b\\\u010c\\\u010d\\\u010e\\\u010f\\\u0110\\\u0111\\\u0112\\\u0113\\\u0114\\\u0115\\\u0116\\\u0117\\\u0118\\\u0119\\\u011a\\\u011b\\\u011c\\\u011d\\\u011e\\\u011f\\\u0120\\\u0121\\\u0122\\\u0123\\\u0124\\\u0125\\\u0126\\\u0127\\\u0128\\\u0129\\\u012a\\\u012b\\\u012c\\\u012d\\\u012e\\\u012f\\\u0130\\\u0131\\\u0132\\\u0133\\\u0134\\\u0135\\\u0136\\\u0137\\\u0138\\\u0139\\\u013a\\\u013b\\\u013c\\\u013d\\\u013e\\\u013f\\\u0140\\\u0141\\\u0142\\\u0143\\\u0144\\\u0145\\\u0146\\\u0147\\\u0148\\\u014a\\\u014b\\\u014c\\\u014d\\\u014e\\\u014f\\\u0150\\\u0151\\\u0152\\\u0153\\\u0154\\\u0155\\\u0156\\\u0157\\\u0158\\\u0159\\\u015a\\\u015b\\\u015c\\\u015d\\\u015e\\\u015f\\\u0160\\\u0161\\\u0162\\\u0163\\\u0164\\\u0165\\\u0166\\\u0167\\\u0168\\\u0169\\\u016a\\\u016b\\\u016c\\\u016d\\\u016e\\\u016f\\\u0170\\\u0171\\\u0172\\\u0173\\\u0174\\\u0175\\\u0176\\\u0177\\\u0178\\\u0179\\\u017a\\\u017b\\\u017c\\\u017d\\\u017e\\\u0218\\\u0219\\\u021a\\\u021b]{1,60}) 
******

In my Groovy code,
In response.JSON I am getting - first_name:?vengers15 which validates fine against the pattern using

*****
    pattern.matcher(val);
    boolean valid =  matcher.matches()
    valid = true
*****

I can guess it's because

*****
    <meta charset="UTF-8">
*****

being handled on UI Framework.

But when I am hitting the API with the same data as above directly through SOAPUI ,Provided the JSON payload with same data as though UI e.g. "first_name": "Àvengers15" . I am getting the same response.JSON as above ,first_name:?vengers15 but the validations fails against the RegEx pattern

*****
    pattern.matcher(val);
    boolean valid =  matcher.matches()
    valid = false
*****

I tried handling UTF-8,thought this might be a problem in my Groovy Service class, but dosen't work.

*****
    byte[] ptext = attrValue.getBytes();
    String valueAfterUtf = new String(ptext, "UTF-8");
*****

Also , tried setting
'Content-Type', 'application/json;charset=UTF-8' in Header , didn't work.

 1. Why am I getting question mark , if UTF-8 has been handled in case of UI.
 2. Why validation is failing through SOAPUI.

Any help would be greatly appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2025-02-07 14:36:28

首先,您需要区分“字符”和“字形”:基本上,字形是一个字符的图形表示,并且在当前字体不包含字形的情况下,系统将向您展示替换字形(图形当前字符的表示)。

因此,首先,您需要检查您看到的问号是问号还是当前字体的替换字形,以备未知字符。

接下来,您需要检查您正在使用的代码集:虽然Unicode及其编码能够显示任何定义的字符,但还有其他编码仅知道子集。现在,当您将一个代码设置为另一个代码的字符串转换为另一个代码时,未知字符通常会被问号替换 - 或者您会遇到某种错误。

因此,要验证字符串的内容的真正含义,您应该显示字符的十六进制值,而不仅仅是使用system.out.println()

First, you need to distinguish between "characters" and "glyphs": basically, a glyph is the graphical representation of a character, and the system will present you a replacement glyph in cases where the current font does not contain a glyph (a graphical representation) for the current character.

So at first you need to check whether the question mark that you see is the question mark or the current font's replacement glyph for unknown characters.

Next you need to check the code sets that you are working with: while Unicode and its encodings are able to present any defined character, there are other encodings that know only subsets. When you now translate a String from one code set into another, unknown characters will be replaced – often by a question mark – or you get an error of some kind.

So for verifying what the contents of your Strings really are, you should display the hex values of the characters, instead of just using System.out.println().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文