@@ -661,22 +661,33 @@ class DateValue extends AsciiStringRepresentation {
661
661
}
662
662
}
663
663
664
- class DecimalString extends AsciiStringRepresentation {
665
- constructor ( ) {
666
- super ( "DS" ) ;
667
- this . maxLength = 16 ;
668
- this . padByte = PADDING_SPACE ;
669
- }
664
+ class NumericStringRepresentation extends AsciiStringRepresentation {
670
665
671
666
readBytes ( stream , length ) {
672
667
const BACKSLASH = String . fromCharCode ( VM_DELIMITER ) ;
673
- const ds = stream . readAsciiString ( length ) ;
674
- if ( ds . indexOf ( BACKSLASH ) !== - 1 ) {
675
- // handle decimal string with multiplicity
676
- return ds . split ( BACKSLASH ) ;
668
+ const numStr = stream . readAsciiString ( length ) ;
669
+ const nums = numStr . split ( BACKSLASH ) ;
670
+
671
+ // final element in list may have a padding byte for even length, this should be removed as it is not part of
672
+ // the original value and prevents max length issues during write
673
+ if ( nums . length > 1 ) {
674
+ const last = nums [ nums . length - 1 ] ;
675
+
676
+ // trim padding byte if last element exceeds length
677
+ if ( last . length > this . maxLength ) {
678
+ nums [ nums . length - 1 ] = last . substring ( 0 , this . maxLength ) ;
679
+ }
677
680
}
678
681
679
- return [ ds ] ;
682
+ return nums ;
683
+ }
684
+ }
685
+
686
+ class DecimalString extends NumericStringRepresentation {
687
+ constructor ( ) {
688
+ super ( "DS" ) ;
689
+ this . maxLength = 16 ;
690
+ this . padByte = PADDING_SPACE ;
680
691
}
681
692
682
693
applyFormatting ( value ) {
@@ -694,6 +705,7 @@ class DecimalString extends AsciiStringRepresentation {
694
705
695
706
convertToString ( value ) {
696
707
if ( value === null ) return "" ;
708
+ if ( typeof value === 'string' ) return value ;
697
709
698
710
let str = String ( value ) ;
699
711
if ( str . length > this . maxLength ) {
@@ -798,25 +810,13 @@ class FloatingPointDouble extends ValueRepresentation {
798
810
}
799
811
}
800
812
801
- class IntegerString extends AsciiStringRepresentation {
813
+ class IntegerString extends NumericStringRepresentation {
802
814
constructor ( ) {
803
815
super ( "IS" ) ;
804
816
this . maxLength = 12 ;
805
817
this . padByte = PADDING_SPACE ;
806
818
}
807
819
808
- readBytes ( stream , length ) {
809
- const BACKSLASH = String . fromCharCode ( VM_DELIMITER ) ;
810
- const is = stream . readAsciiString ( length ) ;
811
-
812
- if ( is . indexOf ( BACKSLASH ) !== - 1 ) {
813
- // handle integer string with multiplicity
814
- return is . split ( BACKSLASH ) ;
815
- }
816
-
817
- return [ is ] ;
818
- }
819
-
820
820
applyFormatting ( value ) {
821
821
const formatNumber = ( numberStr ) => {
822
822
let returnVal = numberStr . trim ( ) . replace ( / [ ^ 0 - 9 . \\ \- + e ] / gi, "" ) ;
@@ -831,6 +831,7 @@ class IntegerString extends AsciiStringRepresentation {
831
831
}
832
832
833
833
convertToString ( value ) {
834
+ if ( typeof value === 'string' ) return value ;
834
835
return value === null ? "" : String ( value ) ;
835
836
}
836
837
0 commit comments