Commit 53d9cc23 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Escape URI value in IMPP property

parent 44aae58b
......@@ -46,9 +46,14 @@ namespace belcard {
};
class BelCardImpp : public BelCardProperty {
private:
std::string _escaped_value;
public:
BELCARD_PUBLIC static std::shared_ptr<BelCardImpp> parse(const std::string& input);
BELCARD_PUBLIC static void setHandlerAndCollectors(belr::Parser<std::shared_ptr<BelCardGeneric>> *parser);
BELCARD_PUBLIC virtual void setValue(const std::string &value);
BELCARD_PUBLIC virtual void serialize(std::ostream &output) const;
BELCARD_PUBLIC BelCardImpp();
};
......
......@@ -23,4 +23,4 @@ libbelcard_la_CXXFLAGS=$(BELR_CFLAGS)
AM_CPPFLAGS=-I$(top_srcdir)/include
libbelcard_la_LIBADD=$(BELR_LIBS) $(BCTOOLBOX_LIBS)
\ No newline at end of file
libbelcard_la_LIBADD=$(BELR_LIBS) $(BCTOOLBOX_LIBS)
......@@ -16,6 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bctoolbox/parser.h>
#include "belcard/belcard.hpp"
#include <belr/parser-impl.cc>
......@@ -84,6 +85,27 @@ BelCardImpp::BelCardImpp() : BelCardProperty() {
setName("IMPP");
}
void BelCardImpp::setValue(const string &value) {
bctbx_noescape_rules_t uri = {0};
bctbx_noescape_rules_add_alfanums(uri);
bctbx_noescape_rules_add_list(uri, ":");
bctbx_noescape_rules_add_list(uri, "@");
_escaped_value = bctbx_escape(value.c_str(), uri);
BelCardProperty::setValue(value);
}
void BelCardImpp::serialize(ostream& output) const {
if (getGroup().length() > 0) {
output << getGroup() << ".";
}
output << getName();
for (auto it = getParams().begin(); it != getParams().end(); ++it) {
output << ";" << (**it);
}
output << ":" << _escaped_value << "\r\n";
}
shared_ptr<BelCardLang> BelCardLang::parse(const string& input) {
return BelCardProperty::parseProperty<BelCardLang>("LANG", input);
}
......
......@@ -16,7 +16,7 @@ belcard_tester_SOURCES=belcard-tester.cpp belcard-tester.hpp \
belcard-rfc6474-tester.cpp \
belcard-vcard-tester.cpp
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la $(BELR_LIBS) -lbcunit -lbctoolbox-tester
belcard_tester_LDADD=$(top_builddir)/src/libbelcard.la $(BELR_LIBS) -lbcunit $(BCTOOLBOX_LIBS) $(BCTOOLBOX_TESTER_LIBS)
belcard_tester_CFLAGS=\
-DBC_CONFIG_FILE=\"config.h\" \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment