1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

help plugin yaml error

Discussion in 'Development' started by Levi, Sep 10, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I get this error when i put
    Code:
    02:06:51 [CRITICAL] ErrorException: "yaml_parse(): reading error encountered during parsing: control characters are not allowed (line 1, column 1)" (EXCEPTION) in "/src/pocketmine/utils/Config" at line 147
    to config.yml
     
  2. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    That's a problem with the encoding. Unfortunately YAML doesn't support UTF-32 (that includes the '§' character). The easiest fix is to replace '§' with a different character like '&'. To do this use the str_replace function, see an example of how to do it here: https://github.com/EvolSoft/CustomA...ts/src/CustomAlerts/CustomAlerts.php#L99-L126
     
    XdmingXD likes this.
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You are using the wrong encoding. If you are using the right encoding, that character works.
    Proof:
    Code:
    $ php -r 'var_dump(yaml_parse("---\nsection: \xc2\xa7\n...\n"));'
    array(1) {
      ["section"]=>
      string(2) "§"
    }
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    In addition, different encodings are supported:
    Code:
    $ php -r '
    foreach([YAML_ANY_ENCODING, YAML_UTF8_ENCODING, YAML_UTF16LE_ENCODING, YAML_UTF16BE_ENCODING] as $e){
        $y = yaml_emit(["ampersand" => "&", "section" => "\xc2\xa7"], $e);
        echo $y, PHP_EOL;
        var_dump(yaml_parse($y));
        echo str_repeat("\n", 32);
    }' | xxd
    00000000: 2d2d 2d0a 616d 7065 7273 616e 643a 2027  ---.ampersand: '
    00000010: 2627 0a73 6563 7469 6f6e 3a20 225c 7841  &'.section: "\xA
    00000020: 3722 0a2e 2e2e 0a0d 0a61 7272 6179 2832  7".......array(2
    00000030: 2920 7b0a 2020 5b22 616d 7065 7273 616e  ) {.  ["ampersan
    00000040: 6422 5d3d 3e0a 2020 7374 7269 6e67 2831  d"]=>.  string(1
    00000050: 2920 2226 220a 2020 5b22 7365 6374 696f  ) "&".  ["sectio
    00000060: 6e22 5d3d 3e0a 2020 7374 7269 6e67 2832  n"]=>.  string(2
    00000070: 2920 22c2 a722 0a7d 0a0a 0a0a 0a0a 0a0a  ) "..".}........
    00000080: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  ................
    00000090: 0a0a 0a0a 0a0a 0a0a 0a2d 2d2d 0a61 6d70  .........---.amp
    000000a0: 6572 7361 6e64 3a20 2726 270a 7365 6374  ersand: '&'.sect
    000000b0: 696f 6e3a 20c2 a70a 2e2e 2e0a 0d0a 6172  ion: .........ar
    000000c0: 7261 7928 3229 207b 0a20 205b 2261 6d70  ray(2) {.  ["amp
    000000d0: 6572 7361 6e64 225d 3d3e 0a20 2073 7472  ersand"]=>.  str
    000000e0: 696e 6728 3129 2022 2622 0a20 205b 2273  ing(1) "&".  ["s
    000000f0: 6563 7469 6f6e 225d 3d3e 0a20 2073 7472  ection"]=>.  str
    00000100: 696e 6728 3229 2022 c2a7 220a 7d0a 0a0a  ing(2) "..".}...
    00000110: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  ................
    00000120: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a fffe  ................
    00000130: 2d00 2d00 2d00 0a00 6100 6d00 7000 6500  -.-.-...a.m.p.e.
    00000140: 7200 7300 6100 6e00 6400 3a00 2000 2700  r.s.a.n.d.:. .'.
    00000150: 2600 2700 0a00 7300 6500 6300 7400 6900  &.'...s.e.c.t.i.
    00000160: 6f00 6e00 3a00 2000 a700 0a00 2e00 2e00  o.n.:. .........
    00000170: 2e00 0a00 0d0a 6172 7261 7928 3229 207b  ......array(2) {
    00000180: 0a20 205b 2261 6d70 6572 7361 6e64 225d  .  ["ampersand"]
    00000190: 3d3e 0a20 2073 7472 696e 6728 3129 2022  =>.  string(1) "
    000001a0: 2622 0a20 205b 2273 6563 7469 6f6e 225d  &".  ["section"]
    000001b0: 3d3e 0a20 2073 7472 696e 6728 3229 2022  =>.  string(2) "
    000001c0: c2a7 220a 7d0a 0a0a 0a0a 0a0a 0a0a 0a0a  ..".}...........
    000001d0: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  ................
    000001e0: 0a0a 0a0a 0a0a feff 002d 002d 002d 000a  .........-.-.-..
    000001f0: 0061 006d 0070 0065 0072 0073 0061 006e  .a.m.p.e.r.s.a.n
    00000200: 0064 003a 0020 0027 0026 0027 000a 0073  .d.:. .'.&.'...s
    00000210: 0065 0063 0074 0069 006f 006e 003a 0020  .e.c.t.i.o.n.:.
    00000220: 00a7 000a 002e 002e 002e 000a 0d0a 6172  ..............ar
    00000230: 7261 7928 3229 207b 0a20 205b 2261 6d70  ray(2) {.  ["amp
    00000240: 6572 7361 6e64 225d 3d3e 0a20 2073 7472  ersand"]=>.  str
    00000250: 696e 6728 3129 2022 2622 0a20 205b 2273  ing(1) "&".  ["s
    00000260: 6563 7469 6f6e 225d 3d3e 0a20 2073 7472  ection"]=>.  str
    00000270: 696e 6728 3229 2022 c2a7 220a 7d0a 0a0a  ing(2) "..".}...
    00000280: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  ................
    00000290: 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a       ..............
    Even BOM is supported!
    Yes, UTF-32 is probably not supported, but UTF-8 and UTF-16 (both BE/LE) are supported. All these contain the section sign. Just convert your encoding!
     
  5. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Shouldn't you still replace it with something else like the ampersand just IN CASE it is changed or modified in the future?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    hax
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Then you should first provide a way to write colors as "&white" rather than "&f" in case it is no longer §f in the future.
     
    Levi likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.