本文介绍了转义 ruby​​ 字符串中的特殊字符以匹配 Salesforce SOQL 要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Rails 应用程序开发 Salesforce 集成,但我遇到了搜索/提交包含特殊字符(如+")的电子邮件的问题.

I am developing a Salesforce integration for a Rails application and I ran into an issue of searching/submitting contacts with emails that include special characters like '+'.

在 Salesforce 文档中,他们提到某些字符是保留字符,需要在每个保留字符之前插入\".详细信息:https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm

Within the Salesforce documentation, they mention that some characters are reserved and a '\' needs to be inserted before each reserved character. Details: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_sosl_find.htm

鉴于 '\' 用于在 Ruby 中转义字符,我无法在不遇到 Salesforce API 问题的情况下将 '\' 添加到保留字符.对于那些为 Rails 实施了 Salesforce 集成的人,你们是如何解决电子邮件中保留字符的问题的?谢谢!

Given that a '\' is used to escape characters in Ruby, I have not been able to add the '\' to a reserved character without running into issues with the Salesforce API. For those who have implemented a Salesforce integration for Rails, how did you solve the issue of reserved characters within emails? Thanks!

推荐答案

您应该转义特殊字符 ?&|!{ } [ ] ( ) ^ ~ * : \ " ' + - 像这样在你的字符串中

You should escape special characters ? & | ! { } [ ] ( ) ^ ~ * : \ " ' + - in your string like this

"email+special@example.net".gsub(/(\?|&|\||\!|\{|\}|\[|\]|\(|\)|\^|\~|\*|\:|\\|\"|\'|\+|\-)/){|special| "\\" + special }

这篇关于转义 ruby​​ 字符串中的特殊字符以匹配 Salesforce SOQL 要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:24