@@ -307,6 +307,7 @@ fn parse_source(element: &Element) -> Result<String, anyhow::Error> {
307307fn parse_context_get ( element : & mut Element ) -> Result < ContextGetResponse , anyhow:: Error > {
308308 let mut properties: Vec < Property > = vec ! [ ] ;
309309 while let Some ( mut child) = element. take_child ( "property" ) {
310+ let encoding = child. attributes . get ( "encoding" ) . map ( |s| s. to_string ( ) ) ;
310311 let p = Property {
311312 name : child. attributes
312313 . get ( "name" )
@@ -329,14 +330,18 @@ fn parse_context_get(element: &mut Element) -> Result<ContextGetResponse, anyhow
329330 size : child. attributes . get ( "size" ) . map ( |s| s. parse :: < u32 > ( ) . unwrap ( ) ) ,
330331 key : child. attributes . get ( "key" ) . map ( |name| name. to_string ( ) ) ,
331332 address : child. attributes . get ( "address" ) . map ( |name| name. to_string ( ) ) ,
332- encoding : child . attributes . get ( " encoding" ) . map ( |s| s . to_string ( ) ) ,
333+ encoding : encoding. clone ( ) ,
333334 children : parse_context_get ( & mut child) . unwrap ( ) . properties ,
334335 value : match child. children . first ( ) {
335- Some ( XMLNode :: CData ( cdata) ) => Some ( String :: from_utf8 (
336- general_purpose:: STANDARD . decode (
337- cdata
338- ) . unwrap_or ( vec ! [ ] )
339- ) . unwrap_or ( "" . to_string ( ) ) ) ,
336+ Some ( XMLNode :: CData ( cdata) ) => Some (
337+ match encoding {
338+ Some ( encoding) => match encoding. as_str ( ) {
339+ "base64" => String :: from_utf8 ( general_purpose:: STANDARD . decode ( cdata) . unwrap ( ) ) . unwrap ( ) ,
340+ _ => cdata. to_string ( ) ,
341+ } ,
342+ _ => cdata. to_string ( ) ,
343+ }
344+ ) ,
340345 _ => None ,
341346 }
342347 } ;
@@ -396,6 +401,7 @@ fn parse_continuation_response(
396401#[ cfg( test) ]
397402mod test {
398403 use super :: * ;
404+ use pretty_assertions:: { assert_eq, assert_ne} ;
399405
400406 #[ test]
401407 fn test_parse_xml ( ) -> Result < ( ) , anyhow:: Error > {
@@ -486,7 +492,17 @@ function call_function(string $hello) {
486492 #[ test]
487493 fn test_parse_context_get ( ) -> Result < ( ) , anyhow:: Error > {
488494 let result = parse_xml (
489- r#"<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="0"><property name="$bar" fullname="$bar" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property><property name="$true" fullname="$true" type="bool"><![CDATA[1]]></property><property name="$this" fullname="$this" type="object" classname="Foo" children="1" numchildren="2" page="0" pagesize="32"><property name="true" fullname="$this->true" facet="public" type="bool"><![CDATA[1]]></property><property name="bar" fullname="$this->bar" facet="public" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property></property></response>"# ,
495+ r#"
496+ <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="4" context="0">
497+ <property name="$bar" fullname="$bar" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property>
498+ <property name="$float" fullname="$float" type="float"><![CDATA[123.4]]></property>
499+ <property name="$int" fullname="$int" type="int"><![CDATA[123]]></property>
500+ <property name="$true" fullname="$true" type="bool"><![CDATA[1]]></property>
501+ <property name="$this" fullname="$this" type="object" classname="Foo" children="1" numchildren="2" page="0" pagesize="32">
502+ <property name="true" fullname="$this->true" facet="public" type="bool"><![CDATA[1]]></property>
503+ <property name="bar" fullname="$this->bar" facet="public" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property>
504+ </property>
505+ </response>"# ,
490506 ) ?;
491507
492508 match result {
@@ -510,6 +526,36 @@ function call_function(string $hello) {
510526 encoding: Some ( "base64" . to_string( ) ) ,
511527 value: Some ( "foo" . to_string( ) ) ,
512528 } ,
529+ Property {
530+ name: "$float" . to_string( ) ,
531+ fullname: "$float" . to_string( ) ,
532+ classname: None ,
533+ page: None ,
534+ pagesize: None ,
535+ property_type: "float" . to_string( ) ,
536+ facet: None ,
537+ size: None ,
538+ children: vec![ ] ,
539+ key: None ,
540+ address: None ,
541+ encoding: None ,
542+ value: Some ( "123.4" . to_string( ) ) ,
543+ } ,
544+ Property {
545+ name: "$int" . to_string( ) ,
546+ fullname: "$int" . to_string( ) ,
547+ classname: None ,
548+ page: None ,
549+ pagesize: None ,
550+ property_type: "int" . to_string( ) ,
551+ facet: None ,
552+ size: None ,
553+ children: vec![ ] ,
554+ key: None ,
555+ address: None ,
556+ encoding: None ,
557+ value: Some ( "123" . to_string( ) ) ,
558+ } ,
513559 Property {
514560 name: "$true" . to_string( ) ,
515561 fullname: "$true" . to_string( ) ,
@@ -523,7 +569,7 @@ function call_function(string $hello) {
523569 key: None ,
524570 address: None ,
525571 encoding: None ,
526- value: Some ( "" . to_string( ) ) ,
572+ value: Some ( "1 " . to_string( ) ) ,
527573 } ,
528574 Property {
529575 name: "$this" . to_string( ) ,
@@ -548,7 +594,7 @@ function call_function(string $hello) {
548594 key: None ,
549595 address: None ,
550596 encoding: None ,
551- value: Some ( "" . to_string( ) ) ,
597+ value: Some ( "1 " . to_string( ) ) ,
552598 } ,
553599 Property {
554600 name: "bar" . to_string( ) ,
0 commit comments