@@ -75,6 +75,26 @@ std::string obtain_guest_id(const std::string & json)
7575 return " guest" + std::to_string (max_id + 1 );
7676}
7777
78+ static std::string escape_turtle_literal (std::string s)
79+ {
80+ // 1) Escape backslashes
81+ for (size_t pos = 0 ; (pos = s.find (' \\ ' , pos)) != std::string::npos; pos += 2 ) {
82+ s.replace (pos, 1 , " \\\\ " );
83+ }
84+
85+ // 2) Escape double quotes
86+ for (size_t pos = 0 ; (pos = s.find (' "' , pos)) != std::string::npos; pos += 2 ) {
87+ s.replace (pos, 1 , " \\\" " );
88+ }
89+
90+ // 3) Optional: normalize newlines (depends on parser strictness)
91+ for (size_t pos = 0 ; (pos = s.find (' \n ' , pos)) != std::string::npos; pos += 2 ) {
92+ s.replace (pos, 1 , " \\ n" );
93+ }
94+
95+ return s;
96+ }
97+
7898void StoreGuestInfo::on_result ()
7999{
80100 RCLCPP_DEBUG (node_->get_logger (), " [StoreGuestInfo] result received" );
@@ -101,6 +121,7 @@ void StoreGuestInfo::on_result()
101121 kb_publisher_->publish (fact_msg);
102122
103123 if (!guest_description_.empty ()) {
124+ guest_description_ = escape_turtle_literal (guest_description_);
104125 fact_msg.data = guest_id + " oro:description \" " + guest_description_ + " \" " ;
105126 kb_publisher_->publish (fact_msg);
106127 }
0 commit comments